<!DOCTYPE html><html lang="cn" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>Linux初级命令 | 碧蓝幻想</title><meta name="author" content="阿尔托莉雅"><meta name="copyright" content="阿尔托莉雅"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="1.连接命令： 云服务器连接： 1ssh root@qv1234.top  centos7IP地址查看： 1ip addr    ## centos的ip地址是ens33条目中的inet值。  ubantuIP地址查看： 1ipconfig  RedHat地址查看 12ip a# 在2：ens160下的inet后面即为  1ip a show ens160  其他命令： 12hostname -i">
<meta property="og:type" content="article">
<meta property="og:title" content="Linux初级命令">
<meta property="og:url" content="http://example.com/2023/03/13/3.linux/A2.Linux%E5%88%9D%E7%BA%A7%E5%91%BD%E4%BB%A4/index.html">
<meta property="og:site_name" content="碧蓝幻想">
<meta property="og:description" content="1.连接命令： 云服务器连接： 1ssh root@qv1234.top  centos7IP地址查看： 1ip addr    ## centos的ip地址是ens33条目中的inet值。  ubantuIP地址查看： 1ipconfig  RedHat地址查看 12ip a# 在2：ens160下的inet后面即为  1ip a show ens160  其他命令： 12hostname -i">
<meta property="og:locale">
<meta property="og:image" content="http://example.com/images/Otherwallpaper/avatar.png">
<meta property="article:published_time" content="2023-03-13T12:32:23.764Z">
<meta property="article:modified_time" content="2023-03-13T12:46:58.032Z">
<meta property="article:author" content="阿尔托莉雅">
<meta property="article:tag" content="Linux">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://example.com/images/Otherwallpaper/avatar.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://example.com/2023/03/13/3.linux/A2.Linux%E5%88%9D%E7%BA%A7%E5%91%BD%E4%BB%A4/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: 'Copy successfully',
    error: 'Copy error',
    noSupport: 'The browser does not support'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: 'Just',
    min: 'minutes ago',
    hour: 'hours ago',
    day: 'days ago',
    month: 'months ago'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Linux初级命令',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-03-13 20:46:58'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/images/Otherwallpaper/avatar.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">Articles</div><div class="length-num">11</div></a><a href="/tags/"><div class="headline">Tags</div><div class="length-num">4</div></a><a href="/categories/"><div class="headline">Categories</div><div class="length-num">2</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/archive/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 工具</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/images/"><i class="fa-fw fas fa-image"></i><span> 图库</span></a></li><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/video/"><i class="fa-fw fas fa-video"></i><span> 视频</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/images/PCwallpaper/backgroud2.jpg')"><nav id="nav"><span id="blog-info"><a href="/" title="碧蓝幻想"><span class="site-name">碧蓝幻想</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/archive/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 工具</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/images/"><i class="fa-fw fas fa-image"></i><span> 图库</span></a></li><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/video/"><i class="fa-fw fas fa-video"></i><span> 视频</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Linux初级命令</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">Created</span><time class="post-meta-date-created" datetime="2023-03-13T12:32:23.764Z" title="Created 2023-03-13 20:32:23">2023-03-13</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">Updated</span><time class="post-meta-date-updated" datetime="2023-03-13T12:46:58.032Z" title="Updated 2023-03-13 20:46:58">2023-03-13</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Linux/">Linux</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Linux初级命令"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">Post View:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="1-连接命令："><a href="#1-连接命令：" class="headerlink" title="1.连接命令："></a>1.连接命令：</h1><ol>
<li><p>云服务器连接：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh root@qv1234.top</span><br></pre></td></tr></table></figure>
</li>
<li><p>centos7IP地址查看：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ip addr    ## centos的ip地址是ens33条目中的inet值。</span><br></pre></td></tr></table></figure>
</li>
<li><p>ubantuIP地址查看：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ipconfig</span><br></pre></td></tr></table></figure>
</li>
<li><p>RedHat地址查看</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">ip a</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">在2：ens160下的inet后面即为</span></span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ip a show ens160</span><br></pre></td></tr></table></figure>
</li>
<li><p>其他命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">hostname -i</span><br><span class="line">alias myip=&quot;ip a | cut -d&#x27; &#x27; -f6 | head -9 | tail -1&quot;   # 执行myip</span><br></pre></td></tr></table></figure></li>
</ol>
<h1 id="2-系统命令："><a href="#2-系统命令：" class="headerlink" title="2.系统命令："></a>2.系统命令：</h1><h2 id="1-主机名配置："><a href="#1-主机名配置：" class="headerlink" title="1.主机名配置："></a>1.主机名配置：</h2><ol>
<li>查看当前主机名：hostname</li>
<li>查看当前主机的FQDN：hostname -f</li>
<li>查看主机名配置文件：cat &#x2F;etc&#x2F;hostname</li>
<li>修改当前主机名（临时修改，重启linux系统之后失效 ）：hostname 新主机名</li>
<li>修改当前主机名（永久修改）：hostnamectl set-hostname  新主机名</li>
</ol>
<h2 id="2-网络服务管理："><a href="#2-网络服务管理：" class="headerlink" title="2.网络服务管理："></a>2.网络服务管理：</h2><ul>
<li><p>用于控制软件服务：systemctl &#x2F; service  [option] 服务名</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>status</td>
<td>查看指定服务的状态</td>
</tr>
<tr>
<td>start</td>
<td>启动指定服务</td>
</tr>
<tr>
<td>stop</td>
<td>停止指定服务</td>
</tr>
<tr>
<td>restart</td>
<td>重启指定服务</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl status docker    # 查询docker服务的状态</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="3-防火墙命令："><a href="#3-防火墙命令：" class="headerlink" title="3.防火墙命令："></a>3.防火墙命令：</h2><ul>
<li><p>用于控制防火墙：systemctl &#x2F; service [option] firewalld</p>
</li>
<li><p>防火墙根据配置文件&#x2F;etc&#x2F;sysconfig&#x2F;iptables 来控制本机的“出”“入”网络访问行为</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>status</td>
<td>查看防火墙状态</td>
</tr>
<tr>
<td>start</td>
<td>启动防火墙</td>
</tr>
<tr>
<td>stop</td>
<td>关闭防火墙</td>
</tr>
<tr>
<td>disable</td>
<td>开机禁用</td>
</tr>
<tr>
<td>enable</td>
<td>开机启用</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl status firewalld</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl start firewalld</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl stop firewalld</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="4-防火墙端口命令："><a href="#4-防火墙端口命令：" class="headerlink" title="4.防火墙端口命令："></a>4.防火墙端口命令：</h2><ul>
<li><p>参数permanent永久生效，没有此参数重启后失效</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">firewall-cmd --zone=public --add-port=8161/tcp --permanent </span><br><span class="line">firewall-cmd --zone=public --add-port=61616/tcp --permanent </span><br></pre></td></tr></table></figure>
</li>
<li><p>重启防火墙：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">firewall-cmd --reload</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看端口是否设置成功：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">firewall-cmd --zone=public --list-ports</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="5-进程管理命令"><a href="#5-进程管理命令" class="headerlink" title="5.进程管理命令"></a>5.进程管理命令</h2><ul>
<li><p>进程的详情：</p>
<table>
<thead>
<tr>
<th>UID</th>
<th>PID</th>
<th>PPID</th>
<th>C</th>
<th>STIME</th>
<th>TTY</th>
<th>TIME</th>
<th>CMD</th>
</tr>
</thead>
<tbody><tr>
<td>root</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>18:25</td>
<td>?</td>
<td>00:00:06</td>
<td>&#x2F;usr&#x2F;lib&#x2F;systemd&#x2F;…..</td>
</tr>
</tbody></table>
<ul>
<li>UID:该进程执行的用户Id</li>
<li>PID：进程ID</li>
<li>PPID：该进程的父级进程Id；如果一个程序的父级进程找不到，该程序的进程称之为僵尸进程</li>
<li>C：CPU的占用率，其形式是百分数</li>
<li>STIME：进行的启动时间</li>
<li>TTY：终端设备，发起该进程的设备识别符号，如果显示？则表示该进程并不是由终端设备发起</li>
<li>TIME：进程的执行时间</li>
<li>CMD：该进程的名称或者对应的路径</li>
</ul>
</li>
<li><p><strong>查看进程：ps [option]</strong></p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-e（ processes）</td>
<td>表示列出所有的进程</td>
</tr>
<tr>
<td>-f（full）</td>
<td>显示全部的列（全字段）</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ps -ef   # 显示所有的进程详情</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ps -ef | grep post   # 查看名为post的进程详情</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>杀死某个进程</strong>：kill 进程ip</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-9</td>
<td>强制杀死进程</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">ps -ef | grep dokcer  # 查询docker进程的信息</span><br><span class="line">kill 75806  # 根据进程ID删除进程</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="6-网络命令："><a href="#6-网络命令：" class="headerlink" title="6.网络命令："></a>6.网络命令：</h2><ul>
<li><p>查看是否ping通过对方主机：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ping</span><br></pre></td></tr></table></figure>

<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-c 数字</td>
<td>用于设定本命令发出的ICMP消息包的数量，若无此选项，则会无限次发送消息包直到用户按【Ctrl+C】组合键才终止命令</td>
</tr>
<tr>
<td>-s 字节数</td>
<td>设置ping命令发出的消息包的大小，默认发送的测试数据大小为56字节；自动添加8字节的ICMP协议头后,显示的是64字节；再添加20字节的IP协议头，则显示的为84字节。最大设置</td>
</tr>
<tr>
<td>-i 时间间隔</td>
<td>设定前后两次发送ICMP消息包之间的时间间隔，无此选项时，默认时间间隔为1秒。为了保障本机和目标主机的安全，一般不要小于0.2秒</td>
</tr>
<tr>
<td>-t</td>
<td>设置存活时间TTL(Time To Live)</td>
</tr>
</tbody></table>
</li>
<li><p>显示网络设备信息：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ifconfig</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看网卡信息：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dhclient</span><br></pre></td></tr></table></figure>
</li>
<li><p>显示详细的网络状况：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">netstart</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="7-其他命令："><a href="#7-其他命令：" class="headerlink" title="7.其他命令："></a>7.其他命令：</h2><ol>
<li><p>查看当前LInux发行版信息：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cat /proc/version</span><br><span class="line">dmesg | grep linux</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">/proc/cmdline         # 保存操作系统的启动参数</span><br><span class="line"></span><br><span class="line">/proc/cpuinfo         # 保存CPU的相关信息。对应lscpu命令。</span><br><span class="line"></span><br><span class="line">/proc/devices         # 系统已经加载的所有块设备和字符设备的信息。</span><br><span class="line"></span><br><span class="line">/proc/diskstats       # 统计磁盘设备的I/O信息。</span><br><span class="line"></span><br><span class="line">/proc/filesystems     # 保存当前系统支持的文件系统。</span><br><span class="line"></span><br><span class="line">/proc/kcore	          # 物理内存的镜像。该文件大小是已使用的物理内存加上4K。</span><br><span class="line"></span><br><span class="line">/proc/loadavg	      # 保存最近1分钟、5分钟、15分钟的系统平均负载。</span><br><span class="line"></span><br><span class="line">/proc/meminfo	      # 保存当前内存使用情况。对应free命令</span><br><span class="line"></span><br><span class="line">/proc/mounts          # 系统中当前挂载的所有文件系统。mount命令。</span><br><span class="line"></span><br><span class="line">/proc/uptime          # 系统自上次启动后的运行时间。</span><br><span class="line"></span><br><span class="line">/proc/version         # 当前系统的内核版本号</span><br><span class="line"></span><br><span class="line">/proc/vmstat          # 当前系统虚拟内存的统计数据</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看内核版本：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">uname -r</span><br></pre></td></tr></table></figure>

<table>
<thead>
<tr>
<th>uname参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-a</td>
<td>显示全部的信息</td>
</tr>
<tr>
<td>-s</td>
<td>显示操作系统名称</td>
</tr>
<tr>
<td>-m</td>
<td>显示处理器类型</td>
</tr>
<tr>
<td>-v</td>
<td>显示操作系统的版本</td>
</tr>
<tr>
<td>-n</td>
<td>显示主机名</td>
</tr>
</tbody></table>
</li>
<li><p>查看shell的类型：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cat /etc/shells</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看当前默认的shell：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">echo $SHELL </span><br></pre></td></tr></table></figure>
</li>
<li><p>查看cpu：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">top</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">top -p（PID）    # 只显示某个进程的信息</span><br><span class="line">top -u（user）   # 查找特定用户启动的进程</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">第一行: 系统时间，运行时间，在线用户数，负载均衡 ——&gt; <span class="built_in">uptime</span>命令</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">第二行：总进程，运行进程，休眠进程，停止进程，僵尸进程</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">第三行：用户空间占用CPU比例，内核空间占用CPU比例等</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">第四行：物理内存总量，空闲内存总量，使用中的内存总量，缓存的内存总量</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">第五行：交换空间总量，空闲交换总量，使用空间，虚拟空间</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">后面为进程表</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>查看cpu的核数：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cat /proc/cpuinfo| grep &quot;cpu cores&quot;| uniq</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看端口：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ss -tnl</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看系统的日志信息：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">路径1：/var/log/messages：记录 Linux 内核消息及各种应用程序的公共日志信息</span><br><span class="line"></span><br><span class="line">路径2：/var/log/cron：记录 crond 计划任务产生的事件信息</span><br><span class="line"></span><br><span class="line">路径3：/var/log/dmesg：记录 Linux 操作系统在引导过程中的各种事件信息</span><br><span class="line"></span><br><span class="line">路径4：/var/log/maillog：记录进入或发出系统的电子邮件活动</span><br><span class="line"></span><br><span class="line">路径5：/var/log/lastlog：记录每个用户最近的登录事件</span><br><span class="line"></span><br><span class="line">路径6：/var/log/secure：记录用户认证相关的安全事件信息</span><br><span class="line"></span><br><span class="line">路径7：/var/log/wtmp：记录每个用户登录、注销及系统启动和停机事件</span><br><span class="line"></span><br><span class="line">路径8：/var/log/btmp：记录失败的、错误的登录尝试及验证事件</span><br></pre></td></tr></table></figure>
</li>
<li><p>系统关机：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">shutdown -h now / poweroff       # 现在关机 </span><br><span class="line">shutdown -t 10                   # 10秒后关机</span><br><span class="line">shutdown -H                      # 半分钟后关机</span><br><span class="line">shutdown -h 10                   # 十秒分钟后关机</span><br><span class="line">shutdown -r                      # 关机后重启</span><br></pre></td></tr></table></figure>
</li>
<li><p>重启计算机：</p>
</li>
</ol>
   <figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">reboot</span><br></pre></td></tr></table></figure>

<h1 id="3-用户和用户组命令："><a href="#3-用户和用户组命令：" class="headerlink" title="3.用户和用户组命令："></a>3.用户和用户组命令：</h1><h2 id="1-用户管理命令"><a href="#1-用户管理命令" class="headerlink" title="1.用户管理命令"></a>1.用户管理命令</h2><ul>
<li><p>Linux下的用户可以分为三类：1.超级用户，2.系统用户，3.普通用户</p>
</li>
<li><p>Linux中的组有以下两类：</p>
<ol>
<li>基本组：建立账户时，若没有指定账户所属的组，系统会建立一个和用户名相同的组，这个组就是基本组。</li>
<li>附加组：可以容纳多个用户，组中的用户都具有组所拥有的权利</li>
</ol>
</li>
<li><p><strong>只有root用户可以进行用户管理命令</strong>。</p>
</li>
<li><p>用户信息的存储</p>
<table>
<thead>
<tr>
<th>用户存储文件</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>&#x2F;etc&#x2F;passwd</td>
<td>存储用户的关键信息</td>
</tr>
<tr>
<td>&#x2F;etc&#x2F;group</td>
<td>存储用户组的关键信息</td>
</tr>
<tr>
<td>&#x2F;etc&#x2F;shadow</td>
<td>存储用户的密码信息</td>
</tr>
<tr>
<td>&#x2F;etc&#x2F;gshadow</td>
<td>存储用户组的密码信息</td>
</tr>
</tbody></table>
</li>
<li><p>&#x2F;etc&#x2F;passwd文件中的信息：</p>
<table>
<thead>
<tr>
<th>用户名</th>
<th>密码</th>
<th>用户ID</th>
<th>用户组ID</th>
<th>注释</th>
<th>家目录</th>
<th>解释器Shell</th>
</tr>
</thead>
<tbody><tr>
<td>itcast</td>
<td>x(不显示)</td>
<td>1000</td>
<td>1000</td>
<td>itcast</td>
<td>&#x2F;home&#x2F;itcsat</td>
<td>&#x2F;bin&#x2F;bash</td>
</tr>
</tbody></table>
<ul>
<li>家目录：用户登录进入系统中之后默认的位置</li>
<li>解释器Shell：等待用户进入系统之后，用户输入指令之后，该解释器会收集用户输入的指令，传递给内核。</li>
</ul>
</li>
<li><p>&#x2F;etc&#x2F;group文件中的信息：</p>
<table>
<thead>
<tr>
<th>组名</th>
<th>组的加密口令</th>
<th>是系统区分不同组的ID</th>
<th>是用“，”分开的用户名，列出的成员以该组为附加组</th>
</tr>
</thead>
<tbody><tr>
<td>root</td>
<td>x(不显示)</td>
<td>0</td>
<td></td>
</tr>
</tbody></table>
</li>
<li><p><strong>添加用户</strong>：useradd [option] 用户名</p>
<table>
<thead>
<tr>
<th>常用参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-g（gid）</td>
<td>指定用户的用户主组，选项值可以是用户组的id，也可以是组名</td>
</tr>
<tr>
<td>-G（groups）</td>
<td>指定用户的用户附加组，选项值可以是用户组的id，也可以是组名（linux一个用户可以属于多个用户组）</td>
</tr>
<tr>
<td>-u（uid）</td>
<td>指定用户自定义的uid，系统默认生成（超级用户的UID：0，系统用户的UID：1～999，普通用户的UID：≥1000）</td>
</tr>
<tr>
<td>-c（comment）</td>
<td>添加注释（表示该用户是干什么的）</td>
</tr>
<tr>
<td>-d（home-dir）</td>
<td>目录——设定用户的家目录(默认为&#x2F;home&#x2F;用户名)</td>
</tr>
<tr>
<td>-e（expiredate）</td>
<td>YYYY-MM-DD——设置用户的失效日期,此日期后将不能使用该账号</td>
</tr>
<tr>
<td>-s（shell）</td>
<td>shell名——指定用户登录后使用的Shell,默认是bash</td>
</tr>
<tr>
<td>-N（no）</td>
<td>不创建与用户名同名的基本组</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">useradd -g 1000 -u 1001 qv123  # 添加qv123用户,用户组ID1000,用户uid10001</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">useradd -s /sbin/nologin sarach    # 设置次用户为不可登录shell</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>修改用户</strong>：usermod [option] 用户名</p>
<table>
<thead>
<tr>
<th>常用参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-g（gid）</td>
<td>指定用户的用户主组，选项值可以是用户组的id，也可以是组名</td>
</tr>
<tr>
<td>-G（groups）</td>
<td>指定用户的用户附加组，选项值可以是用户组的id，也可以是组名（linux一个用户可以属于多个用户组）</td>
</tr>
<tr>
<td>-u（uid）</td>
<td>指定用户自定义的uid，系统默认生成（500之后）</td>
</tr>
<tr>
<td>-l（login）</td>
<td>修改用户名</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">usermod -g 1001 -G 1002 qv123  # 修改qv123用户的用户组ID为1001，用户附加值ID为1002</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">usermod -l wangli qv123   # 修改qv123用户的的用户名为wangli</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">usermod -G g123 itcast   # 修改itcast用户的用户附加值为g123</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>设置 &#x2F; 修改密码：</strong>passwd 用户名</p>
<p>Linux不允许没有密码的用户登录到系统，因此前面创建的用户目前都于锁定状态，需要设置密码之后才能登录计算机</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">passwd                  # 普通用户修改自己密码：</span><br><span class="line">passwd [ 用户名 ]       # 修改普通用户密码（root）</span><br><span class="line">passwd -d [ 用户名 ]    # 删除普通用户密码（root）</span><br><span class="line">echo &quot;123456&quot; | passwd --stdin test1     # 使用管道流修改用户密码</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>切换用户：</strong>su 用户名（如果不指明用户默认切换到root）</p>
<ul>
<li>从root往普通用户切换不需要密码，但是反之则需要root密码</li>
<li>切换用户之后前后的工作路径是不变的</li>
<li>普通用户没有办法访问root用户家目录，但是反之则可以；</li>
<li>su和su - 命令区别就是加载的配置文件不一样：<ul>
<li>su 切换方式加载的文件： ~&#x2F;.bashrc，&#x2F;etc&#x2F;bashrc </li>
<li>su - 切换方式加载的文件： &#x2F;etc&#x2F;bashrc，&#x2F;etc&#x2F;profile，<del>&#x2F;.bashrc，</del>&#x2F;.bash_profile</li>
</ul>
</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">su qv123</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>删除用户：</strong>userdel [option] 用户名</p>
<ul>
<li>已经登录的qv123用户删除的时候提示删除失败，但是没有登录的list用户可以正常删除；但可以kill qv123的用户相关的进程，再删除已登录的用户。</li>
</ul>
<table>
<thead>
<tr>
<th>常用参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-r（remove）</td>
<td>表示删除用户，同时其家用录</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">userdel -r qv123   # 删除qv123用户，并且删除qv123目录</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>查看用户名</strong>：whoami </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">whoami  # 显示当前登录的用户名</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>查看用户信息</strong>：id 用户名</p>
<p>查看一个用户的一些基本信息（包含用户id，用户组id，附加组id），该指令如果不指定用户则默认当前用户</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">id    # 查看当前用户的基本信息</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[root@qv123 qv123]# id huang123    # 查看指定用户的基本信息</span><br><span class="line">uid=1002(huang123) gid=1005(base1) groups=1005(base1),1006(add1)</span><br></pre></td></tr></table></figure>




</li>
<li><p><strong>控制用户对系统命令的使用权限</strong>:</p>
<ul>
<li><p>使用 sudo 命令可以提高普通用户的操作权限，不过这个权限<strong>需要root用户进行配置&#x2F;etc&#x2F;sudoers文件</strong>才可使用。</p>
</li>
<li><p>当用户执行sudo时，便会让用户输入自己的密码来确认（root执行sudo时不需要输入密码）；</p>
</li>
<li><p>若用户具有执行sudo的权限，便开始sudo后续接的命令</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[qv110@wangxuan root]$ sudo yum install -y httpd</span><br></pre></td></tr></table></figure>

<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>l（list）</td>
<td>列出当前用户可以执行的命令。只有在sudoers里的用户才能使用该选项。</td>
</tr>
<tr>
<td>u（user）</td>
<td>以指定用户的身份执行命令。后面的用户是除root以外的，可以是用户名，也可以是UID</td>
</tr>
<tr>
<td>k（reset）</td>
<td>清除存活期时间，下次再使用sudo时要再输入密码。</td>
</tr>
<tr>
<td>b（backgroud）</td>
<td>在后台执行指定的命令。</td>
</tr>
<tr>
<td>p（prompt）</td>
<td>可以更改询问密码的提示语，其中%u会代换为使用者账号名称，%h会显示主机名称</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[qv110@wangxuan root]$ sudo -l</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[qv110@wangxuan root]$ sudo -u qv456 pwd</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[qv110@wangxuan root]$ sudo -k</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[qv110@wangxuan root]$ sudo -b yum install -y httpd</span><br></pre></td></tr></table></figure>
</li>
<li><p>配置&#x2F;etc&#x2F;sudoers文件</p>
<table>
<thead>
<tr>
<th>用户账号</th>
<th>登录者的来源主机名</th>
<th>可切换的身份</th>
<th>可执行的命令</th>
</tr>
</thead>
<tbody><tr>
<td>root</td>
<td>ALL</td>
<td>ALL</td>
<td>ALL</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]# vim /etc/sudoers</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">qv123 ALL=(ALL) ALL</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
<h2 id="2-用户组管理命令："><a href="#2-用户组管理命令：" class="headerlink" title="2.用户组管理命令："></a>2.用户组管理命令：</h2><ul>
<li><p>每个用户都有一个用户组，系统可以对一个用户组中的所有用户进行集中。</p>
</li>
<li><p>Linux系统对用户组的规则有所不同，如<strong>Linux下的用户属于与它同名的用户组，这个用户组在创建用户时同时创建</strong></p>
</li>
<li><p>用户组的管理涉及用户组的添加，删除和修改。组的增加，删除和修改实际上就是对&#x2F;etc&#x2F;group文件的更新。</p>
<table>
<thead>
<tr>
<th>用户组名</th>
<th>密码</th>
<th>用户组ID</th>
<th>组内用户名(用户的附加组)</th>
</tr>
</thead>
<tbody><tr>
<td>itcast</td>
<td>x(不显示)</td>
<td>1000</td>
<td>itcast</td>
</tr>
</tbody></table>
<p><img src="C:\Users\user\AppData\Roaming\Typora\typora-user-images\image-20220621234538017.png" alt="image-20220621234538017"></p>
</li>
<li><p><strong>用户组的添加：</strong>groupadd [option] 用户组名</p>
<table>
<thead>
<tr>
<th>常用参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-g（gid）</td>
<td>表示选择自己设置一个自定义的用户组ID数组（默认系统自动添加）</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">groupadd -g 1001 g123  # 添加一个g123的用户组，用户组ID为1001</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>用户组的编辑：</strong>groupmod [option] 用户组名</p>
<table>
<thead>
<tr>
<th>常用参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-g（gid）</td>
<td>表示选择自己设置一个自定义的用户组ID数组（默认系统自动添加）</td>
</tr>
<tr>
<td>-n（name）</td>
<td>表示设置新的用户组的名称</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">groupmod -n p1 g123  # 修改一个g123的用户组，新的用户组名p1</span><br></pre></td></tr></table></figure>
</li>
<li><p>添加&#x2F;删除组成员：gpasswd [选项] [用户] [组]（只有root用户和组管理员才能够使用该命令）</p>
<table>
<thead>
<tr>
<th>常用参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-r（delete passwd）</td>
<td>删除组密码</td>
</tr>
<tr>
<td>-a（add）</td>
<td>把用户加入组</td>
</tr>
<tr>
<td>-d（delete user）</td>
<td>把用户从组中删除。</td>
</tr>
<tr>
<td>-M（member）</td>
<td>可同时添加多个用户</td>
</tr>
<tr>
<td>-A（admin）</td>
<td>给组指派管理员</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@wangxuan ~]# gpasswd -r test1</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@wangxuan ~]# gpasswd -a qv110 qv456</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@wangxuan ~]# gpasswd -A qv110 qv110</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@wangxuan ~]# gpasswd -M qv110,qv456,mysql test1</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@wangxuan ~]# gpasswd -d qv456 test1</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>用户组的删除：</strong>groupdel 用户组名</p>
<p>如果需要删除一个组，但是这个组是某个用户的主组时，则不允许删除；如果确实需要删除，则先从组内移出所有用户。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">groupdel g123</span><br></pre></td></tr></table></figure>
</li>
<li><p>查询用户的用户组信息：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[root@qv123 redhat]# groups redhat   # 显示出用户的所属组信息</span><br><span class="line">redhat : g1</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="3-查看用户登录系统的情况："><a href="#3-查看用户登录系统的情况：" class="headerlink" title="3.查看用户登录系统的情况："></a>3.查看用户登录系统的情况：</h2><ul>
<li><p>users：查看当前登录系统的用户</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[root@node12 ~]# users</span><br><span class="line">root</span><br></pre></td></tr></table></figure>
</li>
<li><p>lastlog：如果想要知道每个账号的最近登录时间，则可使用lastlog查看，该命令会读取&#x2F;var&#x2F;log&#x2F;lastlog文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@node13 ~]# lastlog</span><br><span class="line">Username Port   From          Latest</span><br><span class="line">root     pts/0  192.168.168.1 Mon May 9 15:38:52 +0800 2022</span><br></pre></td></tr></table></figure>
</li>
<li><p>w：显示登录到系统的用户信息</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]# w</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">USER：表示登录系统的用户</span><br><span class="line">TTY：表示用户使用的TTY名称</span><br><span class="line">FROM：表示用户从哪里登录进来</span><br><span class="line">LOGIN@：用户登录的日期和时间</span><br><span class="line">idle：表示空闲时间</span><br><span class="line">JCPU：在某段时间内所有与该终端相关的进程任务所耗费的cpu时间</span><br><span class="line">PCPU：当前活动进程使用的系统时间</span><br><span class="line">WHAT：表示当前用户执行的进程名称和选项</span><br></pre></td></tr></table></figure>
</li>
<li><p>who：显示目前登录到系统的用户，who通常通过&#x2F;var&#x2F;run&#x2F;utmp文件来获取信息</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-s</td>
<td>仅显示名称、终端、时间字段信息和主机名。这是who默认的输出</td>
</tr>
<tr>
<td>-b</td>
<td>列出系统最近启动的日期</td>
</tr>
<tr>
<td>-m</td>
<td>列出关于当前终端的信息</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</tbody></table>
</li>
</ul>
<h1 id="4-常用命令："><a href="#4-常用命令：" class="headerlink" title="4.常用命令："></a>4.常用命令：</h1><h2 id="1-列出某目录文件列表："><a href="#1-列出某目录文件列表：" class="headerlink" title="1.列出某目录文件列表："></a>1.列出某目录文件列表：</h2><table>
<thead>
<tr>
<th>文件类型</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-</td>
<td>普通文件</td>
</tr>
<tr>
<td>l</td>
<td>符号链接又叫软链接，和原文件不是一个文件；例如Windows的快捷方式</td>
</tr>
<tr>
<td>d</td>
<td>目录</td>
</tr>
<tr>
<td>c</td>
<td>字符设备文件：串行端口设备，顺序读写，键盘</td>
</tr>
<tr>
<td>p</td>
<td>管道文件 ：用于进程间的通信</td>
</tr>
<tr>
<td>s</td>
<td>套接字文件：通常用于网络上的通信</td>
</tr>
</tbody></table>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">文件类型 权限          所属者 所属组 文件大小  创建时间       文件名称</span><br><span class="line">d       r-xr-xr-x.  2 root   root  36864    4月  28 18:17  bin</span><br><span class="line">d       rwxr-xr-x.  2 root   root  22       4月  28 18:06  config</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">ls              ## 显示本目录所有文件以及文件夹</span><br><span class="line">ls ../          ## 显示上一层目录所有文件以及文件夹</span><br><span class="line">ls -a           ## 显示所有文件（包括隐藏）以及文件夹</span><br><span class="line">ls -l 或 ll     ## 显示所有文件的详细信息以及文件夹</span><br><span class="line">ls -lh          ## 显示所有文件的详细信息以及文件夹(以文件大小)</span><br></pre></td></tr></table></figure>

<table>
<thead>
<tr>
<th>选项</th>
<th>功能</th>
</tr>
</thead>
<tbody><tr>
<td><strong>-l</strong>（long）</td>
<td>以长格形式显示文件和目录的详细信息,ls命令默认只显示名称的短格式。</td>
</tr>
<tr>
<td><strong>-d</strong>（directory）</td>
<td>显示指定目录本身的信息,而不显示目录下的各个文件和子目录的信息。</td>
</tr>
<tr>
<td>-c（ctime）</td>
<td>按文件的修改时间排序后，予以显示。</td>
</tr>
<tr>
<td><strong>-h</strong></td>
<td></td>
</tr>
<tr>
<td>-R（recursive）</td>
<td>以递归的方式显示指定目录及其子目录中的所有内容。</td>
</tr>
<tr>
<td>-a（all）</td>
<td>显示所有子目录和文件的信息,包括名称以“.”开头的隐藏目录和隐藏文件。</td>
</tr>
<tr>
<td>-A</td>
<td>与-a选项的作用类似,但不显示表示当前目录的“.”和表示父目录的“..”。</td>
</tr>
<tr>
<td>-i</td>
<td><strong>显示文件索引节点号（inode）</strong></td>
</tr>
<tr>
<td>-s（sort by file size）</td>
<td>按照文件大小排序</td>
</tr>
</tbody></table>
<h2 id="2-切换目录命令："><a href="#2-切换目录命令：" class="headerlink" title="2.切换目录命令："></a>2.切换目录命令：</h2><ol>
<li>切换到本目录下的app目录：cd app</li>
<li>切换到上层目录：cd ..   </li>
<li>打开上一层目录下的某一目录：cd ..&#x2F;目录</li>
<li>切换到某一目录：cd &#x2F;目录1&#x2F;目录2… </li>
<li>切换到用户主目录：cd ~  或 cd 或 cd $HOME</li>
<li>切换到上一次所在的目录：cd -</li>
</ol>
<h2 id="3-创建目录和移除目录："><a href="#3-创建目录和移除目录：" class="headerlink" title="3.创建目录和移除目录："></a>3.创建目录和移除目录：</h2><ol>
<li><p>创建目录：mkdir [option] [dirname]</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-m</td>
<td>对新建目录设置存储权限，也可以用chmod命令设置</td>
</tr>
<tr>
<td>-p（parents）</td>
<td>dirname可以是一个路径名称。一次可以建立多个目录（多个层级）</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mkdir test1   # 在本目录下创建test1的目录</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mkdir test1 test2 test3   # 在本目录下创建test1,test2,test3的多个目录</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mkdir -p -m 700 ./inin/mail   # 在本目录下创建多层目录/inin/mail，并指明权限</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">文件命名规则：</span><br><span class="line">1.不能使用/来当文件名，/是用来做根的，也是用来做路径分隔符的</span><br><span class="line">2.文件名不能超过255个字符</span><br><span class="line">3.区分大小写file File FILE fIle</span><br><span class="line">4.目录也是文件，在同一路径下，两个不同类型文件不能同名</span><br></pre></td></tr></table></figure>


</li>
<li><p>删除空目录：rmdir [option] [dirname]</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-r（recursive，递归）</td>
<td>带文件（删除指定目录下的所有文件）</td>
</tr>
<tr>
<td>-f（force，推进）</td>
<td>不询问</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rmdir test1   # 删除当前目录下的一个空目录</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rmdir -p /usr/local/app  # 删除/usr/local/app如果父目录不为空则保留</span><br></pre></td></tr></table></figure></li>
</ol>
<h2 id="4-创建文件，删除文件，查看文件详情："><a href="#4-创建文件，删除文件，查看文件详情：" class="headerlink" title="4.创建文件，删除文件，查看文件详情："></a>4.创建文件，删除文件，查看文件详情：</h2><ul>
<li><p>查看文件的详细信息：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">stat [文件名 / 路径名]</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Access: 2022-06-09 11:19:35.484027446 +0800    ## 即access time，查看了一下文件内容（cat），文件的atime时间会更新</span><br><span class="line">Modify: 2022-04-16 14:46:36.153011877 +0800    ## 即modify time，文件内容被改变了，ctime会更新</span><br><span class="line">Change: 2022-04-16 14:46:36.153011877 +0800    ## 即change time，元数据【文件的属性，例如大小、文件名等等】被改变，mtime会更新</span><br></pre></td></tr></table></figure>
</li>
<li><p>创建一个空文件（<strong>如果文件已存在，更新文件的三个时间</strong>）：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">touch 文件</span><br><span class="line">touch 目录1/目录2/文件</span><br><span class="line">touch file&#123;1..3&#125;   # 创建从file1到file3的文件</span><br></pre></td></tr></table></figure>
</li>
<li><p>创建链接文件：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ln -s 原文件 目标文件     ## 创建软链接文件</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[root@iZ8vb3lp570ckxhpbpeopuZ qv123]# ln -s b.txt d.txt</span><br><span class="line">[root@iZ8vb3lp570ckxhpbpeopuZ qv123]# ll</span><br><span class="line">-rw-r--r-- 2 root root  0 10月 11 15:21 a.txt</span><br><span class="line">-rw-r--r-- 1 root root  0 10月 11 15:21 b.txt</span><br><span class="line">-rw-r--r-- 2 root root  0 10月 11 15:21 c.txt</span><br><span class="line">lrwxrwxrwx 1 root root  5 10月 11 15:22 d.txt -&gt; b.txt</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ln 原文件 目标文件        ## 创建硬链接文件</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[root@iZ8vb3lp570ckxhpbpeopuZ qv123]# ln a.txt c.txt</span><br><span class="line">[root@iZ8vb3lp570ckxhpbpeopuZ qv123]# ll</span><br><span class="line">-rw-r--r-- 2 root root  0 10月 11 15:21 a.txt</span><br><span class="line">-rw-r--r-- 1 root root  0 10月 11 15:21 b.txt</span><br><span class="line">-rw-r--r-- 2 root root  0 10月 11 15:21 c.txt</span><br></pre></td></tr></table></figure>
</li>
<li><p>删除文件：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">rm 文件名1 文件2 ...</span><br><span class="line">rm -f 文件名1 文件2 ...   # 删除文件不咨询</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="5-显示文件内容命令："><a href="#5-显示文件内容命令：" class="headerlink" title="5.显示文件内容命令："></a>5.显示文件内容命令：</h2><ol>
<li><p>查看文件的所有内容或连接文件（不分页）：cat [option] 文件名</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-v</td>
<td>用于一种特殊形式显示控制字符</td>
</tr>
<tr>
<td>-n（number）</td>
<td>对输出内容中进行标注行号。</td>
</tr>
<tr>
<td>-b(nonblank，非空白行)</td>
<td>对输出内容中<strong>非空行</strong>进行标注行号</td>
</tr>
<tr>
<td>-T（tabs）</td>
<td>将TAB显示为 ^I。该选项要与 -v 选项一起使用，即如果没有 -v选项，则这个选项将将被忽略</td>
</tr>
<tr>
<td>-E</td>
<td>在每行的末尾显示一个 $ 符，该选项要与 -v 选项一起使用</td>
</tr>
<tr>
<td>-u（ignore）</td>
<td>输出不经过缓冲区</td>
</tr>
<tr>
<td>-A(all)</td>
<td>等同于 -vET</td>
</tr>
<tr>
<td>-t</td>
<td>等同于 -vT</td>
</tr>
<tr>
<td>-e（equivalent，相等的）</td>
<td>等同于 -vE</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cat Readme.txt   # 显示出Readme.txt文件的内容</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cat -A Readme.txt   # 显示出Readme.txt文件的内容;如果文件中含有特殊字符的话，一起显示出来</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cat test1 test2 &gt; test3  # 把test1和test2的文件内容合并起来，放入test3中</span><br></pre></td></tr></table></figure>


</li>
<li><p>查看文件内容（<strong>分页显示</strong>）：more [option] 文件名 （回车下一行，空格下一屏，q退出（如果没有内容会退出））</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-p（page）</td>
<td>显示下一屏之前先清屏</td>
</tr>
<tr>
<td>-c</td>
<td>作用同 -p 类似</td>
</tr>
<tr>
<td>-d</td>
<td>在每屏的底部显示 –more– (XX%) …</td>
</tr>
<tr>
<td>-s</td>
<td>文件中连续的空白行压缩成一个空白行显示</td>
</tr>
<tr>
<td>-f</td>
<td>显示当前问价你的文件名和行数</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">more Readme.txt   # 用分页的方式显示出Readme.txt文件的内容</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">more -dc Readme.txt   # 用分页的方式显示出Readme.txt文件的内容；但显示之前要清屏</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">more -c -10 Readme.txt   # 用分页的方式显示出Readme.txt文件的内容;要求每10行显示一次，且显示之前要清屏</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看文件内容（<strong>前后翻页分页显示</strong>）：less 文件名（上下键翻页，q退出（如果没有内容不会退出））</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">less Readme.txt   # 用分页的方式显示出Readme.txt文件的内容；并且可以前后翻页</span><br></pre></td></tr></table></figure>


</li>
<li><p>（<strong>前</strong>）查看文件的前几行信息：head -number 文件名</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">head -3 test.java</span><br></pre></td></tr></table></figure>
</li>
<li><p>（<strong>后</strong>）查看文件最后10行内容：tail -num 文件名</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>+num</td>
<td>从文件第num行以后开始显示</td>
</tr>
<tr>
<td>-num</td>
<td>从文件倒数第num行开始显示；如果省略num参数，系统默认值为10</td>
</tr>
<tr>
<td>c（char）</td>
<td>以字节为num的计数单位</td>
</tr>
<tr>
<td>-f（follow）</td>
<td>使tail不停地去读取和显示文件最新的内容, 这样有实</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tail -4 test.java   </span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tail -c +0 group</span><br></pre></td></tr></table></figure></li>
</ol>
<h2 id="6-查看文件内容命令："><a href="#6-查看文件内容命令：" class="headerlink" title="6.查看文件内容命令："></a>6.查看文件内容命令：</h2><ul>
<li><h3 id="grep命令："><a href="#grep命令：" class="headerlink" title="grep命令："></a>grep命令：</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">返回的行信息</span></span><br><span class="line">grep [option] [search pattern] [file1,file2,....]</span><br><span class="line">erep [option] [search pattern] [file1,file2,....]</span><br><span class="line">frep [option] [search pattern] [file1,file2,....]</span><br></pre></td></tr></table></figure>

<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-b</td>
<td>在输出的每一行显示包含匹配字符串的行在文件中的字节偏移量</td>
</tr>
<tr>
<td>-c（count）</td>
<td>仅显示找到的行数</td>
</tr>
<tr>
<td>-i（ignore）</td>
<td>显示找到的行，比较时不区分大小写</td>
</tr>
<tr>
<td>-h</td>
<td>在查找多个文件时，指示grep不要将文件名加入到输出之前</td>
</tr>
<tr>
<td>-l</td>
<td>显示首次匹配串所在的文件名并用换行符将其隔开。</td>
</tr>
<tr>
<td>-n（line-number）</td>
<td><strong>显示找到的行，显示行号</strong>（文件首行行号为1）</td>
</tr>
<tr>
<td>-o（only-matching）</td>
<td>只显示匹配的内容</td>
</tr>
<tr>
<td>-A</td>
<td>如果匹配成功，则将匹配行及其后n行一起打印出来</td>
</tr>
<tr>
<td>-B</td>
<td>如果匹配成功，则将匹配行及其前n行一起打印出来</td>
</tr>
<tr>
<td>-C</td>
<td>如果匹配成功，则将匹配行及其前后n行一起打印出来</td>
</tr>
<tr>
<td><strong>-E</strong></td>
<td>等于egrep，扩展</td>
</tr>
<tr>
<td>–color</td>
<td>高亮颜色显示匹配到的字符串</td>
</tr>
<tr>
<td>-v（invert，反向）</td>
<td>显示没有匹配字符串的行</td>
</tr>
<tr>
<td><strong>-x</strong>（line-regexp）</td>
<td>只显示整行严格匹配的行</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grep &#x27;text file&#x27; Readme.txt   # 在文件Readme.txt中搜索字符串&#x27;text file&#x27;</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grep &#x27;text file&#x27; *   # 在所有文件中搜索字符串&#x27;text file&#x27;</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grep &#x27;text file&#x27; *.java   # 在所有的.java文件中搜索字符串&#x27;text file&#x27;-</span><br></pre></td></tr></table></figure>

<p>使用特殊符号进行字符串的匹配</p>
<table>
<thead>
<tr>
<th>匹配模式</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>grep h 文件名</td>
<td>查找文件里有字符h的行</td>
</tr>
<tr>
<td>grep ^q 文件名</td>
<td>显示匹配以q开始的行</td>
</tr>
<tr>
<td>grep ^[ ^q ] 文件名</td>
<td>显示不匹配以q开头的行</td>
</tr>
<tr>
<td>grep ^[0-9] 文件名</td>
<td>显示匹配以数字开头的行</td>
</tr>
<tr>
<td>grep q$ 文件名</td>
<td>显示匹配以q结束的行</td>
</tr>
<tr>
<td>grep ^$</td>
<td><strong>显示空白行</strong></td>
</tr>
<tr>
<td>grep -r h .&#x2F;*</td>
<td>如果要明确搜索当前目录中的子目录有h的行</td>
</tr>
<tr>
<td>grep -d skip h .&#x2F;*</td>
<td>忽略当前目录下的子目录下的普通文件</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grep ^SELINUX /etc/selinux/config    # 查找以SELINUX开头的行数据</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grep ^$ passwd    # 显示要一个文件中空行</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grep ^[^$] passwd   # 显示要一个文件中空行 </span><br></pre></td></tr></table></figure>
</li>
<li><h3 id="cut命令：用于按列提取文本内容"><a href="#cut命令：用于按列提取文本内容" class="headerlink" title="cut命令：用于按列提取文本内容"></a>cut命令：用于按列提取文本内容</h3><table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-d[num]（delimiter，分隔符）</td>
<td>设置间隔符号</td>
</tr>
<tr>
<td>-f[num1,num2…..]（fields）</td>
<td>显示列数</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cut -d: -f1 passwd    # 显示文件中以:分隔，第一列数据</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cut -d&#x27; &#x27; -f1 passwd    # 显示文件中以空格分隔，第一列数据</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cut -d&#x27; &#x27; -f 1-3 passwd    # 显示文件中以空格分隔，第一列到第三列的数据</span><br></pre></td></tr></table></figure>
</li>
<li><p>Sort命令：<strong>默认会按照字母顺序进行排序</strong></p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-f（ignore-case）</td>
<td><strong>忽略大小写</strong></td>
</tr>
<tr>
<td>-b（ignore-leading-blanks）</td>
<td>忽略缩进与空格</td>
</tr>
<tr>
<td>-n（number）</td>
<td><strong>以数值型排序</strong></td>
</tr>
<tr>
<td>-r（reverse）</td>
<td><strong>反向排序</strong></td>
</tr>
<tr>
<td>-u</td>
<td><strong>去除重复行</strong></td>
</tr>
<tr>
<td>-t</td>
<td>指定间隔符</td>
</tr>
<tr>
<td>-k</td>
<td>设置字段范围</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[root@kongd ~]# sort fruit.txt </span><br><span class="line">apple </span><br><span class="line">banana </span><br><span class="line">orange </span><br><span class="line">pear </span><br><span class="line">raspaberry</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@kongd ~]# sort -u sort.txt    # 去重行</span><br><span class="line">Free Linux Lessons </span><br><span class="line">Red Hat certified </span><br><span class="line">Welcome to kongd.com</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">[root@kongd ~]# sort -n number.txt     # 以数值型排序</span><br><span class="line">3</span><br><span class="line">9</span><br><span class="line">12</span><br><span class="line">24</span><br><span class="line">45</span><br><span class="line">56</span><br><span class="line">67</span><br><span class="line">82</span><br><span class="line">98</span><br></pre></td></tr></table></figure>
</li>
<li><h3 id="uniq命令：去除文本中连续的重复行"><a href="#uniq命令：去除文本中连续的重复行" class="headerlink" title="uniq命令：去除文本中连续的重复行"></a>uniq命令：去除文本中连续的重复行</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">uniq passwd</span><br></pre></td></tr></table></figure>
</li>
<li><h3 id="tr命令：替换文件中的字符显示"><a href="#tr命令：替换文件中的字符显示" class="headerlink" title="tr命令：替换文件中的字符显示"></a>tr命令：替换文件中的字符显示</h3><table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-c</td>
<td>反选设定字符。也就是符合 SET1 的部份不做处理，不符合的剩余部份才进行转换</td>
</tr>
<tr>
<td>-d</td>
<td>删除指令字符</td>
</tr>
<tr>
<td>-s</td>
<td>缩减连续重复的字符成指定的单个字符</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cat /etc/passwd | tr a-z A-Z   # 将文件/etc/passwd中的小写字母全部转换成大写字母</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cat /etc/passwd | tr &#x27;123&#x27; &#x27;abc&#x27;    </span><br></pre></td></tr></table></figure>
</li>
<li><h3 id="wc命令：用于统计指定文本文件的行数、字数或字节数"><a href="#wc命令：用于统计指定文本文件的行数、字数或字节数" class="headerlink" title="wc命令：用于统计指定文本文件的行数、字数或字节数"></a>wc命令：用于统计指定文本文件的行数、字数或字节数</h3><table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-l</td>
<td>只显示行数</td>
</tr>
<tr>
<td>-w</td>
<td>只显示单词数</td>
</tr>
<tr>
<td>-c</td>
<td>只显示字节数</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wc -l /etc/passwd</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="7-文件查找："><a href="#7-文件查找：" class="headerlink" title="7.文件查找："></a>7.文件查找：</h2><ul>
<li><h3 id="find命令：可按照文件名、大小、时间、权限、类型、所属者、所属组来搜索文件（返回文件路径）"><a href="#find命令：可按照文件名、大小、时间、权限、类型、所属者、所属组来搜索文件（返回文件路径）" class="headerlink" title="find命令：可按照文件名、大小、时间、权限、类型、所属者、所属组来搜索文件（返回文件路径）"></a>find命令：可按照文件名、大小、时间、权限、类型、所属者、所属组来搜索文件（返回文件路径）</h3><table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-name</td>
<td>匹配名称</td>
</tr>
<tr>
<td>-size</td>
<td>匹配文件的大小（+50KB为查找超过50KB的文件，而-50KB为查找小于50KB的文件）</td>
</tr>
<tr>
<td>-mtime -num</td>
<td>匹配修改内容的时间（-4指小于等于4天内的文件名；+4,大于等于5天前的文件名；4指前4~5那一天的文件）</td>
</tr>
<tr>
<td>-atime -num</td>
<td>匹配访问文件的时间</td>
</tr>
<tr>
<td>-ctime -num</td>
<td>匹配修改文件权限的时间</td>
</tr>
<tr>
<td>-perm</td>
<td>匹配权限（mode为完全匹配，-mode为包含即可）</td>
</tr>
<tr>
<td>-user</td>
<td>匹配所有者</td>
</tr>
<tr>
<td>-group</td>
<td>匹配所有组</td>
</tr>
<tr>
<td>-type</td>
<td>匹配文件类型（b块设备、d目录、c字符设备、p管道、l查找软链接文件、f文本文件）</td>
</tr>
<tr>
<td>-a &#x2F; -o &#x2F; -not</td>
<td>逻辑运算符 ，and 逻辑与，   or 逻辑或，not 逻辑非</td>
</tr>
<tr>
<td>-exec …. \</td>
<td>后面可跟用于进一步处理搜索结果的命令（{}表示找到的文件路径）</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">find . -name &#x27;server.log&#x27;   # 查找当前目录下及其子目录下的server.log文件</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">find / -name &#x27;*oot*&#x27;   # 查找根目录下及其子目录下的文件名有boot的文件</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">find ./ -size +50k</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">find . -mtime -4     # 查找当前目录下及其子目录下的文件内容时间小于4天的文件</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">find . -type l      # 查找当前目录下及其子目录下的文件类型为链接文件的文件</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">find . -name &#x27;a*&#x27; -a -name &#x27;*.txt&#x27;   # 查找当前目录下及其子目录下的同时满足文件名是a开头和.txt结尾的文件</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">find . -user root -a -name &#x27;a*&#x27;   # 查找当前目录下及其子目录下的同时满足文件名是a开头和所有者为root的文件</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">找出当前目录下文件名为<span class="string">&#x27;passwd&#x27;</span>的文件并复制到上一层目录</span></span><br><span class="line">find . -name &#x27;passwd&#x27; -exec cp &#123;&#125; ../ \;</span><br></pre></td></tr></table></figure>

<table>
<thead>
<tr>
<th>其他选项</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-print</td>
<td>默认动作，将搜索结果写入到标准输出</td>
</tr>
<tr>
<td>-fprint file</td>
<td>将搜索结果写入到文件file</td>
</tr>
<tr>
<td>-ls</td>
<td>以详细格式（长格式）显示搜索结果</td>
</tr>
<tr>
<td>-fls file</td>
<td>将搜索结果以详细格式（长格式）写入到文件file</td>
</tr>
<tr>
<td>-delete</td>
<td>将搜索到的文件删除</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</tbody></table>
</li>
<li><h3 id="which命令：which-是搜索系统命令的可执行文件"><a href="#which命令：which-是搜索系统命令的可执行文件" class="headerlink" title="which命令：which 是搜索系统命令的可执行文件"></a>which命令：which 是搜索系统命令的可执行文件</h3></li>
</ul>
<h2 id="8-解压缩和压缩："><a href="#8-解压缩和压缩：" class="headerlink" title="8.解压缩和压缩："></a>8.解压缩和压缩：</h2><ul>
<li><h3 id="tar命令："><a href="#tar命令：" class="headerlink" title="tar命令："></a>tar命令：</h3><table>
<thead>
<tr>
<th>必选选项</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-f（file）</td>
<td>用于指定操作的文件名。</td>
</tr>
</tbody></table>
<table>
<thead>
<tr>
<th>（三选一）必选参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-c（create）</td>
<td>创建打包或者压缩文件</td>
</tr>
<tr>
<td>-x（extract，取出）</td>
<td>释放打包或者压缩文件</td>
</tr>
<tr>
<td>-t（list）</td>
<td>查看包中的文件列表</td>
</tr>
</tbody></table>
<table>
<thead>
<tr>
<th>辅助选项</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-v（verbose）</td>
<td>表示在命令执行时显示详细的提示信息</td>
</tr>
<tr>
<td>-p（）</td>
<td>打包时保留文件及目录的权限</td>
</tr>
<tr>
<td>-z</td>
<td>调用gzip程序，以gzip格式压缩或解压缩文件（.tar.gz）</td>
</tr>
<tr>
<td>-j</td>
<td>调用bzip2程序，以bzip2格式压缩或解压缩文件（.tar.bz2）</td>
</tr>
<tr>
<td>-J</td>
<td>使用xz压缩或解压缩文件（.tar.xz），xz的压缩率通常比bzip2更高</td>
</tr>
<tr>
<td>-C（大写字母C）</td>
<td>和-x选项一起使用，表示释放包时指定释放的目标路径</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tar -cvf 压缩名.tar 目录名    # 打包目录文件 </span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tar -zcvf 压缩名.tar.gz 目录名    # 打包压缩目录文件</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tar -zxvf 压缩名.tar.gz     # 解压缩到当前目录</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tar -zxvf 压缩名.tar.gz -C ./文件     # 解压缩到某目录</span><br></pre></td></tr></table></figure>
</li>
<li><h3 id="zip命令（压缩）："><a href="#zip命令（压缩）：" class="headerlink" title="zip命令（压缩）："></a>zip命令（压缩）：</h3><table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-r（reverse）</td>
<td>将当前目录下的某个目录连同目录下文件一起压缩</td>
</tr>
<tr>
<td>-m（move）</td>
<td>向压缩文件中【】中添加【】文件</td>
</tr>
<tr>
<td>-d（delete）</td>
<td>删除压缩文件中的文件</td>
</tr>
<tr>
<td>-x（exclude）</td>
<td>压缩文件时排除某个文件</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">zip test1.zip test1.txt      # 使用zip压缩文件test1.txt</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">zip -r dir1.zip dir1/       # 将当前目录dir1连同目录下文件一起压缩</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">zip -m test1.zip test2.txt   # 向压缩文件中test1.zip中添加test2. txt文件</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">zip -d test1.zip test2.txt   # 删除压缩文件中的文件</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">zip test.zip *.txt -x test1.txt   # 压缩文件时排除某个文件</span><br></pre></td></tr></table></figure>
</li>
<li><h3 id="unzip命令（解压缩）："><a href="#unzip命令（解压缩）：" class="headerlink" title="unzip命令（解压缩）："></a>unzip命令（解压缩）：</h3><table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-d（directory）</td>
<td>将压缩文件在指定目录下解压缩</td>
</tr>
<tr>
<td>-v（verbose）</td>
<td>查看压缩文件目录，但不解压</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">unzip test2.zip    # 解压文件test2.zip</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">unzip test.zip -d dir1    # 将压缩文件text.zip在指定目录dir1下解压缩</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">unzip -v test.zip      # 查看压缩文件目录，但不解压</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="11-文件目录剪切和复制命令："><a href="#11-文件目录剪切和复制命令：" class="headerlink" title="11.文件目录剪切和复制命令："></a>11.文件目录剪切和复制命令：</h2><ol>
<li><p>复制文件到某目录：cp [option] [src_file | src_dir]   [dst_file | dst_dir]</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-a</td>
<td>通常在拷贝目录时使用。它保留链接、文件属性，并递归地拷贝目录</td>
</tr>
<tr>
<td>-d</td>
<td>复制时保留连接</td>
</tr>
<tr>
<td>-f</td>
<td>在覆盖已经存在的目标文件时不提示</td>
</tr>
<tr>
<td>-i</td>
<td>在覆盖目标文件之前将给出提示要求用户确认</td>
</tr>
<tr>
<td>-p</td>
<td>不只复制文件内容，还会复制修改时间和访问权限</td>
</tr>
<tr>
<td>-r</td>
<td>复制目标目录下的所有子目录和文件</td>
</tr>
<tr>
<td>-l</td>
<td>不做复制，只是连接文件</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cp test1.java /usr/local/app/  # 复制test1.java到/usr/local/app/</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cp test1.java /usr/local/app/test2.java  # 复制test1.java到/usr/local/app/并改名为test2.java</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cp -r /usr/local/app/ /home  # 复制/usr/local/app/下所有子目录文件到/home</span><br></pre></td></tr></table></figure>
</li>
<li><p>剪切文件到某某目录（绝对路径+改名）：mv cp [option] [src_file | src_dir]   [dst_file | dst_dir]</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-i</td>
<td>交互式操作，如果剪切目录有已存在的文件，提示是否覆盖</td>
</tr>
<tr>
<td>-f</td>
<td>禁止交互式操作</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mv /usr/local/* .  # 将/usr/local/下所有子目录和文件剪切到当前目录</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mv test1.java test2.java  # 将当前目录下test1.java改名为test2.java</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mv jdk-linux-x64.tar.gz /usr/local/qv123/jdk    # 将当前目录的jdk压缩包剪切到此路径</span><br></pre></td></tr></table></figure></li>
</ol>
<h2 id="12-时间操作命令："><a href="#12-时间操作命令：" class="headerlink" title="12.时间操作命令："></a>12.时间操作命令：</h2><h3 id="1-date命令："><a href="#1-date命令：" class="headerlink" title="1.date命令："></a>1.date命令：</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">date                          ## 查看当前时间</span><br><span class="line">date &quot;+%j&quot;                    ## 查看今天是当年中的第几天</span><br><span class="line">date &quot;+%Y-%m-%d %H:%M:%S&quot;     ## 按照“年-月-日 小时:分钟:秒”的格式查看当前系统时间</span><br><span class="line">date &quot;+%F&quot;                    ## 查看当前时间，完整日期格式，等价于 %Y-%m-%d</span><br><span class="line">date -s &quot;20201101 8:30:00&quot;    ## 将系统的当前时间设置为2020年11月1日8点30分</span><br></pre></td></tr></table></figure>

<ul>
<li><table>
<thead>
<tr>
<th><strong>参数</strong></th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>%Y</td>
<td>完整年份（例如：2020）</td>
</tr>
<tr>
<td>%M</td>
<td>月份（1~12）</td>
</tr>
<tr>
<td>%D</td>
<td>本月中的第几天</td>
</tr>
<tr>
<td>%H</td>
<td>小时（00～23）</td>
</tr>
<tr>
<td>%M</td>
<td>分钟（00～59）</td>
</tr>
<tr>
<td>%S</td>
<td>秒</td>
</tr>
<tr>
<td>%j</td>
<td>今年中的第几天</td>
</tr>
<tr>
<td>%F</td>
<td>完整日期格式，等价于 %Y-%m-%d</td>
</tr>
</tbody></table>
</li>
</ul>
<h3 id="2-timedatectl命令："><a href="#2-timedatectl命令：" class="headerlink" title="2.timedatectl命令："></a>2.<strong>timedatectl</strong>命令：</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">timedatectl status                              ## 查看系统时间与时区</span><br><span class="line">timedatectl set-timezone Asia/Shanghai          ## 列出上海地区的日期</span><br><span class="line">timedatectl set-time 2021-05-18                 ## 设置系统日期</span><br><span class="line">timedatectl set-time 9:30                       ## 设置系统时间</span><br></pre></td></tr></table></figure>

<table>
<thead>
<tr>
<th>参数</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>status</td>
<td>显示状态信息</td>
</tr>
<tr>
<td>list-timezones</td>
<td>列出已知时区</td>
</tr>
<tr>
<td>set-timezone</td>
<td>设置生效时区</td>
</tr>
<tr>
<td>set-time</td>
<td>设置系统时间</td>
</tr>
</tbody></table>
<h2 id="13-查看命令帮助命令："><a href="#13-查看命令帮助命令：" class="headerlink" title="13.查看命令帮助命令："></a>13.查看命令帮助命令：</h2><ul>
<li><p>查看bash<strong>内置命令</strong>帮助，如：cd</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">help [命令]</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看bash<strong>外置命令</strong>帮助，如：ls</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[命令] ——help</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">示例如下：cat [OPTION]... [FILE]... 表明cat后面可以加上多个可选的选项以及多个可选的文件参数</span><br><span class="line">下面是对于命令的语法的一些符号的说明： </span><br><span class="line">[] ：表示的是可选 ...： 表示的可以存在多个参数 </span><br><span class="line">|表示是可选的 </span><br><span class="line">&lt;&gt;:必填 </span><br><span class="line">&#123;&#125;：表示作为一个整体存在的</span><br></pre></td></tr></table></figure>
</li>
<li><p>提供在线帮助1，使用权限是所有用户</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">man [命令]</span><br></pre></td></tr></table></figure>

<ul>
<li><p>在man命令帮助信息的界面中，所包含的常用操作按键如下：</p>
<table>
<thead>
<tr>
<th><strong>按键</strong></th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>空格键，PaGe down</td>
<td>向下翻一页</td>
</tr>
<tr>
<td>PaGe up，b</td>
<td>向上翻一页</td>
</tr>
<tr>
<td>home</td>
<td>直接前往首页</td>
</tr>
<tr>
<td>end</td>
<td>直接前往尾页</td>
</tr>
<tr>
<td>&#x2F;</td>
<td>从上至下搜索某个关键词，如“&#x2F;linux”</td>
</tr>
<tr>
<td>?</td>
<td>从下至上搜索某个关键词，如“?linux”</td>
</tr>
<tr>
<td>n</td>
<td>定位到下一个搜索到的关键词</td>
</tr>
<tr>
<td>N</td>
<td>定位到上一个搜索到的关键词</td>
</tr>
<tr>
<td>q</td>
<td>退出帮助文档</td>
</tr>
</tbody></table>
</li>
<li><p>man命令的帮助信息的结构如下：</p>
<table>
<thead>
<tr>
<th><strong>结构名称</strong></th>
<th>代表意义</th>
</tr>
</thead>
<tbody><tr>
<td>NAME</td>
<td>命令的名称</td>
</tr>
<tr>
<td>SYNOPSIS</td>
<td>参数的大致使用方法</td>
</tr>
<tr>
<td>DESCRIPTION</td>
<td>介绍说明</td>
</tr>
<tr>
<td>EXAMPLES</td>
<td>演示（附带简单说明）</td>
</tr>
<tr>
<td>OVERVIEW</td>
<td>概述</td>
</tr>
<tr>
<td>DEFAULTS</td>
<td>默认的功能</td>
</tr>
<tr>
<td>OPTIONS</td>
<td>具体的可用选项（带介绍）</td>
</tr>
<tr>
<td>ENVIRONMENT</td>
<td>环境变量</td>
</tr>
<tr>
<td>FILES</td>
<td>用到的文件</td>
</tr>
<tr>
<td>SEE ALSO</td>
<td>相关的资料</td>
</tr>
<tr>
<td>HISTORY</td>
<td>维护历史与联系方式</td>
</tr>
</tbody></table>
</li>
</ul>
</li>
<li><p>提供在线帮助2，使用权限是所有用户（与man page不同的是，info page则是将文件数据拆成一个一个的段落）</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">info [命令]</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="14-其他命令："><a href="#14-其他命令：" class="headerlink" title="14.其他命令："></a>14.其他命令：</h2><ol>
<li><strong>显示当前所在目录</strong>：pwd</li>
<li>补全命令和参数：TAB键</li>
<li>终止当前进程：Ctrl+C</li>
<li>清屏：clear 或 Ctrl+L</li>
<li>移动到当前行的开头：Ctrl+a </li>
<li>移动到当前行的结尾：Ctrl+e</li>
</ol>
<h2 id="15-修改字符集编码："><a href="#15-修改字符集编码：" class="headerlink" title="15.修改字符集编码："></a>15.修改字符集编码：</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">echo &quot;export LC_ALL=en_US.UTF8&quot; &gt;&gt; /etc/profile</span><br><span class="line">source /etc/profile</span><br></pre></td></tr></table></figure>



<h1 id="5-Vi和Vim编辑器："><a href="#5-Vi和Vim编辑器：" class="headerlink" title="5.Vi和Vim编辑器："></a>5.Vi和Vim编辑器：</h1><ul>
<li><p>VIM 是 vi 的升级版本，除了兼容 vi 的所有指令，VIM 还具有一些新的特性，主要体现在：</p>
<p>1.多级撤销：我们知道在 vi 里，按 u 只能撤消上次命令，而在 VIM 里可以无限制的撤消。</p>
<p>2.易用性：vi 只能运行于 unix 中，而 VIM 不仅可以运行于 unix,windows ,mac 等多操作平台。</p>
<p>3.语法加亮：VIM 可以用不同的颜色加亮显示代码。</p>
<p>4.可视化操作：VIM 不仅可以在终端运行，也可以运行于 x window、 mac os、 windows</p>
</li>
</ul>
<img src="C:\Users\user\AppData\Roaming\Typora\typora-user-images\image-20221013095402041.png" alt="image-20221013095402041" style="zoom:67%;" />

<ol>
<li><p>进入文件：vim 文件</p>
</li>
<li><p>切换到命令模式：Esc键</p>
</li>
<li><p>命令模式切换到插入模式：</p>
<table>
<thead>
<tr>
<th>按键参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>i</td>
<td>在光标前插入</td>
</tr>
<tr>
<td>I（大写字母i）</td>
<td>在光标所在行行首第一个非空字符前插入</td>
</tr>
<tr>
<td>A</td>
<td>在光标所在行末尾插入</td>
</tr>
<tr>
<td>o</td>
<td>在光标所在行下一行插入</td>
</tr>
<tr>
<td>O</td>
<td>在光标所在行上一行插入</td>
</tr>
<tr>
<td>S（大写字母）</td>
<td>删除当前行并进入插入模式</td>
</tr>
</tbody></table>
<table>
<thead>
<tr>
<th>光标跳转按键</th>
<th><strong>功能</strong></th>
</tr>
</thead>
<tbody><tr>
<td>^</td>
<td>光标跳转至行首</td>
</tr>
<tr>
<td>$</td>
<td>光标跳转至行尾</td>
</tr>
<tr>
<td>gg</td>
<td>文档首行第一个字符</td>
</tr>
<tr>
<td>G</td>
<td>文档最后一行第一个字符</td>
</tr>
<tr>
<td>行号gg 或者 行号G</td>
<td>跳转到指定行</td>
</tr>
</tbody></table>
<table>
<thead>
<tr>
<th>复制、粘贴、删除按钮</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>dd</td>
<td><strong>删除光标所在行</strong></td>
</tr>
<tr>
<td>ndd</td>
<td>删除从光标处开始的n行</td>
</tr>
<tr>
<td>d^</td>
<td>删除光标前至行首字符</td>
</tr>
<tr>
<td>d$</td>
<td>删除光标及之后的所有字符</td>
</tr>
<tr>
<td>yy</td>
<td>复制光标所在行</td>
</tr>
<tr>
<td>nyy</td>
<td>复制从光标处开始的n行</td>
</tr>
<tr>
<td>p</td>
<td>将缓冲区的内容粘贴到光标所在行的下一行</td>
</tr>
<tr>
<td>u</td>
<td>撤销操作</td>
</tr>
</tbody></table>
</li>
<li><p>命令行切换到末行模式，使用” :或者&#x2F; “：</p>
<table>
<thead>
<tr>
<th>查找关键字并替换按键</th>
<th>功能</th>
</tr>
</thead>
<tbody><tr>
<td>&#x2F;word</td>
<td>从上而下在文件中查找字符串“word”（可按n键定位到下一个匹配的被查找字符串）</td>
</tr>
<tr>
<td>:s &#x2F;old&#x2F;new</td>
<td>将<strong>当前行中</strong>查找到的第一个字符串“old”替换为“new”</td>
</tr>
<tr>
<td>:s &#x2F;old&#x2F;new&#x2F;g</td>
<td>将<strong>当前行中</strong>查找到的所有字符串“old”替换为“new”</td>
</tr>
<tr>
<td>:n1,n2 s&#x2F;old&#x2F;new&#x2F;g</td>
<td>在行号“n1,n2”范围内替换所有的字符串“old”为“new”</td>
</tr>
<tr>
<td>:% s&#x2F;old&#x2F;new&#x2F;g</td>
<td>将整个文件内的字符串“old”替换为“new”</td>
</tr>
</tbody></table>
<table>
<thead>
<tr>
<th>其他操作按键</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>:r &#x2F;dir&#x2F;file</td>
<td>在当前文件中读入其他文件内容</td>
</tr>
<tr>
<td>:sp &#x2F;dir&#x2F;file</td>
<td>可分屏显示另一个文件（光标在多个文件之间的切换按ctrl+w w）</td>
</tr>
<tr>
<td>:g&#x2F;word&#x2F;d</td>
<td>查找含有”word”的行并删除</td>
</tr>
<tr>
<td>:set nu</td>
<td><strong>显示行号</strong></td>
</tr>
<tr>
<td>:set nonu</td>
<td><strong>关闭行号显示</strong></td>
</tr>
<tr>
<td>:n1,n2 d</td>
<td>删除n1-n2行内容</td>
</tr>
<tr>
<td>:n1,n2 co n</td>
<td>复制n1-n2行到第n行后面</td>
</tr>
</tbody></table>
<table>
<thead>
<tr>
<th>保存退出按键</th>
<th>功能</th>
</tr>
</thead>
<tbody><tr>
<td>:q</td>
<td>退出vi&#x2F;vim编辑器，未对文件做任何编辑操作才可退出</td>
</tr>
<tr>
<td>:q!</td>
<td>不保存文档内容，强制退出vi&#x2F;vim编辑器</td>
</tr>
<tr>
<td>:w</td>
<td>保存文件</td>
</tr>
<tr>
<td>:w &#x2F;dir&#x2F;file</td>
<td>将文件另存为&#x2F;dir&#x2F;file</td>
</tr>
<tr>
<td>:wq 或者 ZZ</td>
<td>保存文件内容并退出vi&#x2F;vim编辑器</td>
</tr>
<tr>
<td>:wq!</td>
<td>强制保存并退出</td>
</tr>
</tbody></table>
</li>
</ol>
<h1 id="6-数据流和重定向输出-gt-和-gt-gt-："><a href="#6-数据流和重定向输出-gt-和-gt-gt-：" class="headerlink" title="6.数据流和重定向输出&gt;和&gt;&gt;："></a>6.数据流和重定向输出&gt;和&gt;&gt;：</h1><ul>
<li><p>数据流：</p>
<ul>
<li>标准输入（standard input，简称stdin）：默认情况下，标准输入指从键盘获取的输入，<strong>代码为0</strong></li>
<li>标准输出（standard output，简称stdout）：默认情况下，命令执行所回传正确的信息会输出到屏幕上，<strong>代码为1</strong></li>
<li>标准错误输出（standard error output，简称stderr）：默认情况下，标准错误输出可理解为命令执行失败后，所回传的错误信息会输出到屏幕上，<strong>代码为2</strong></li>
</ul>
</li>
<li><p>重定向：</p>
<table>
<thead>
<tr>
<th><strong>使用形式</strong></th>
<th>功能</th>
</tr>
</thead>
<tbody><tr>
<td>命令 &gt;文件 或 命令 1&gt;文件</td>
<td>将命令执行后的标准输出信息不在默认的屏幕上显示，若指定的文件不存在，则自动创建该文件</td>
</tr>
<tr>
<td>命令 2&gt;文件</td>
<td>将命令执行后所产生的错误信息不在默认的屏幕上显示，若指定的文件不存在，则自动创建该文件</td>
</tr>
<tr>
<td>命令 2&gt;&#x2F;dev&#x2F;null</td>
<td>将命令执行后所产生的错误信息不在默认的屏幕上显示，<strong>而是写入到空设备文件中，即将输出的错误信息丢弃掉</strong></td>
</tr>
<tr>
<td>命令 &amp;&gt;文件或命令 &gt;&amp;文件</td>
<td>将命令执行后的正确输出信息和错误信息不在默认的屏幕上显示，若指定的文件不存在，则自动创建该文件</td>
</tr>
<tr>
<td>命令 &gt;&gt;文件</td>
<td><strong>将命令执行后的正确输出信息以追加的方式写入到指定的文件中，不覆盖原文件内容</strong>，若指定的文件不存在，则自动创建该文件</td>
</tr>
<tr>
<td>命令 &lt;文件</td>
<td><strong>使命令从指定的文件中读取数据作为输入</strong></td>
</tr>
<tr>
<td>命令 &lt;&lt;结束 标识字符串</td>
<td><strong>在命令行读取数据作为输入，直到遇到指定的结束标识字符串</strong></td>
</tr>
</tbody></table>
</li>
<li><p>输出重定向：</p>
<ul>
<li><p>“ &gt; “：覆盖输出，会覆盖到之前的文件内容</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cat test1.txt &gt; test2.txt   # 将test.txt打印到控制台的内容将写到test2.txt中</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ls &gt; test2.txt  # 将ls打印到控制台的内容将写到test2.txt中</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sed  &#x27;s/AAA/BBB/g&#x27;  xyz &gt; xyz.tmp   # 替换文件中的所有AAA成BBB</span><br></pre></td></tr></table></figure>

</li>
<li><p>“ &gt;&gt; “：追加输出，不会覆盖掉原始文件，会在原始文件末尾继续添加</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cat test1.txt &gt;&gt; test2.txt   # 将test.txt打印到控制台的内容追加到test2.txt中</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><p>输入重定向：</p>
<ul>
<li><p>从文件读取数据作为cat命令的输入</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cat &lt; file</span><br></pre></td></tr></table></figure>
</li>
<li><p>标准输入重定向 &lt;&lt; 并不表示追加，而是表示输入结束的意思，即作为一个结束符。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cat &gt; file3 &lt;&lt; end</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[root@iZ8vb3lp570ckxhpbpeopuZ qv123]# cat &gt; a.txt &lt;&lt; end</span><br><span class="line"><span class="meta prompt_">&gt; </span><span class="language-bash">qq</span></span><br><span class="line"><span class="meta prompt_">&gt; </span><span class="language-bash">qq</span></span><br><span class="line"><span class="meta prompt_">&gt; </span><span class="language-bash">end</span></span><br><span class="line">[root@iZ8vb3lp570ckxhpbpeopuZ qv123]# cat a.txt</span><br><span class="line">qq</span><br><span class="line">qq</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><p>echo命令用于在终端设备上输出字符串或变量提取后的值</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]# echo kongd.com</span><br><span class="line">kongd.com</span><br><span class="line">[root@master test]# echo test &gt; /root/test/file     ## 将标准输出重定向到文件</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>tee</strong>读取标准输入的数据，并将其内容输出到文件的同时输出到屏幕</p>
<p><img src="C:\Users\user\AppData\Roaming\Typora\typora-user-images\image-20221012180201469.png" alt="image-20221012180201469"></p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-a或–append</td>
<td>附加到现有文件的后面，而非覆盖它</td>
</tr>
<tr>
<td>-i或–ignore-interrupts</td>
<td>忽略中断信号</td>
</tr>
<tr>
<td>–help</td>
<td>在线帮助</td>
</tr>
</tbody></table>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@iZ8vb3lp570ckxhpbpeopuZ qv123]# ls | tee a.txt</span><br><span class="line">a.txt</span><br><span class="line">jdk</span><br></pre></td></tr></table></figure></li>
</ul>
<h1 id="7-管道命令："><a href="#7-管道命令：" class="headerlink" title="7.管道命令："></a>7.管道命令：</h1><ul>
<li><p>作用：将前一个命令的输出作后一个命令的输入</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ls --help | more     # 分页查看帮助信息</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ps -ef | grep java   # 名称中包含java的进程</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cut -d: -f1 passwd | sort -n    # 查看文件中以：分隔得第一行数据，并按照从小到大排序</span><br></pre></td></tr></table></figure></li>
</ul>
<h1 id="8-Linux的权限命令："><a href="#8-Linux的权限命令：" class="headerlink" title="8.Linux的权限命令："></a>8.Linux的权限命令：</h1><h2 id="1-文件的一般权限："><a href="#1-文件的一般权限：" class="headerlink" title="1.文件的一般权限："></a>1.文件的一般权限：</h2><ul>
<li><p>Linux chmod（英文全拼：change mode）命令是控制用户对文件的权限的命</p>
</li>
<li><p>代表文件文件类型：1.-表示文件  2.d表示文件夹  3.l表示连接</p>
</li>
<li><p>用户具有该文件的权限分类：</p>
<table>
<thead>
<tr>
<th>文件权限</th>
<th>代表数字</th>
</tr>
</thead>
<tbody><tr>
<td>r：read读</td>
<td>4</td>
</tr>
<tr>
<td>w：write写</td>
<td>2</td>
</tr>
<tr>
<td>x：excute执行</td>
<td>1</td>
</tr>
</tbody></table>
</li>
<li><p>Linux&#x2F;Unix 的文件调用权限分为三级 : 文件所有者（Owner）、用户组（Group）、其它用户（Other Users）</p>
</li>
<li><p>文件权限管理用户分类：</p>
<table>
<thead>
<tr>
<th>用户分类</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>u（owner）</td>
<td>属主</td>
</tr>
<tr>
<td>g（group）</td>
<td>属组</td>
</tr>
<tr>
<td>o（other users）</td>
<td>其他用户</td>
</tr>
<tr>
<td>a（all）</td>
<td>所有用户</td>
</tr>
</tbody></table>
<p> <img src="C:\Users\user\AppData\Roaming\Typora\typora-user-images\image-20220619225947970.png" alt="image-20220619225947970"></p>
<p> <img src="C:\Users\user\AppData\Roaming\Typora\typora-user-images\image-20220619230210640.png" alt="image-20220619230210640"></p>
<p> <img src="C:\Users\user\AppData\Roaming\Typora\typora-user-images\image-20221016145206662.png" alt="image-20221016145206662"></p>
</li>
<li><p>操作符号：</p>
<table>
<thead>
<tr>
<th>操作符号</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>+</td>
<td>添加某个权限</td>
</tr>
<tr>
<td>-</td>
<td>取消某个权限</td>
</tr>
<tr>
<td>&#x3D;</td>
<td>赋予给定权限并取消其他权限</td>
</tr>
</tbody></table>
</li>
<li><p><strong>文字设定法：</strong></p>
<ul>
<li><p>添加或删除用户权限：chmod [who] [+]-[&#x3D;] [mode] filename</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chmod a+x test.java   # 给所有用户添加权限可执行</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chmod o-w passwd     # 取消其他组用户的读权限</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chmod ug+w,o-x test.java  # 给当前用户和当前组用户添加写权限，给其他用户删除可执行权限</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chmod u=rwx,g=r,o=rw server.log   # 赋予owner用户读写执行权限，group用户读权限，其他用户读写权限</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看文件的用户权限：ls -l 或ll</p>
</li>
</ul>
</li>
<li><p><strong>数字设定法：</strong></p>
<ul>
<li><p>添加或删除用户权限：chmod [mode] filename</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chmod 644 test.java   # 赋予owner用户读写权限，group用户写权限，其他用户写权限</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chmod 750 test.java   # 赋予owner用户读写可执行，group用户读可执行权限，其他用户没有权限</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看文件的用户权限：ls -l 或ll</p>
</li>
</ul>
</li>
<li><p>修改文件或目录的属主和属组（-R 可递归设置指定目录下的全部文件（包括子目录和子目录中的文件）的所属关系）</p>
<ul>
<li><p>修改文件或目录的所属者：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chown [选项] 新属主:新属组 文件或目录</span><br></pre></td></tr></table></figure>
</li>
<li><p>修改文件或目录的属组：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chown [选项] :新属组 文件或目录</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chgrp [选项] 新属组 文件或目录</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
<h2 id="2-文件和目录的特殊权限："><a href="#2-文件和目录的特殊权限：" class="headerlink" title="2.文件和目录的特殊权限："></a>2.文件和目录的特殊权限：</h2><ul>
<li><p>在Linux系统中，用户对文件或目录的访问权限除了r、w、x三种一般权限外，还有SET UID(SUID)、SET GID(SGID)、Sticky Bit(粘滞位)三种特殊权限，用于对文件或目录进行更加灵活方便的访问控制</p>
</li>
<li><p><strong>SUID权限：</strong>是为了让一般用户在执行某些程序的时候， 在程序的运行期间， <strong>暂时</strong>获得该程序文件所属者的权限。 </p>
</li>
<li><p><strong>SGID权限：</strong></p>
<ul>
<li>文件： 如 果 SGID 设置在二进制文件上， 则不论用户是谁，在执行该程序的时候，<strong>程序的所属组将会变成该程序文件的所属组</strong></li>
<li>目录， 如 果 SGID 是设置在 A 目录上， 则在 A 目录内所建立的文件或目录的所属组， 将会是此 A目录的所属组</li>
</ul>
</li>
<li><p><strong>Sticky Bit权限：</strong>当前只针对目录有效， 对文件没有效果</p>
<ul>
<li>在 具 有 SBit 的目录下， 用户若在该目录下具有 w 及 x 权限 ， 则当用户在该目录下建立文件或目录时， 只有文件拥有者与 root 才有权力删除。</li>
</ul>
</li>
<li><p><strong>设置文件和目录的特殊权限</strong>:</p>
<ul>
<li><p>文字设定法：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chmod a=trwx 文件名</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">使用“u±s”、“g±s”、“o±t”的字符权限模式分别用于添加和移除SUID、GUID、sticky权限</span><br></pre></td></tr></table></figure>
</li>
<li><p>文字设定法：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chmod 1777 文件名</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">若使用数字形式的权限模式,可采用“nnnn”格式的四位八进制数字表示</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">后面三位是一般权限的数字表示，前面第一位则是特殊权限的标志数字</span></span><br><span class="line">0——表示不设置特殊权限</span><br><span class="line">1——表示只设置sticky</span><br><span class="line">2——表示只设置GUID权限</span><br><span class="line">3——表示只设置SGID和sticky权限</span><br><span class="line">4——表示只设置SUID权限</span><br><span class="line">5——表示只设置SUID和sticky权限</span><br><span class="line">6——表示只设置SUID和SGID</span><br><span class="line">7——表示同时设置SUID、GUID、sticky3种权限</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><p>查看文件是否含有特殊权限：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">权限后有.即为拥有特殊权限</span></span><br><span class="line">drwsr-sr-x. 2 root temp     6 Oct 16 22:27 dir</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="3-ACL权限-（指定用户权限）"><a href="#3-ACL权限-（指定用户权限）" class="headerlink" title="3.ACL权限:（指定用户权限）"></a>3.ACL权限:（指定用户权限）</h2><ul>
<li><p>ACL 权限分配：给指定的用户指定目录分配指定的权限</p>
</li>
<li><p>查看ACL权限：getfacl 文件名</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">getfacl cw   </span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">注意如下所示，如果某个目录或文件下有 + 标志，说明其具有 acl 权限。</span></span><br><span class="line">[root@kongd ~]# ll -d /project/ </span><br><span class="line">drwxrwx---+ 2 root QQgroup 6 12月 30 14:15 /project/   </span><br></pre></td></tr></table></figure>
</li>
<li><p>设定ACL权限：setfacl 选项 文件名</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-m（modify）</td>
<td>设定 ACL 权限。如果是给予用户 ACL 权限，则使用 u:用户名:权限 格式赋予；如果是给予组ACL 权限，则使用 g:组名:权限” 格式赋予；</td>
</tr>
<tr>
<td>-x（remove）</td>
<td>删除指定的 ACL 权限</td>
</tr>
<tr>
<td>-b（remove）</td>
<td>删除所有的 ACL 权限</td>
</tr>
<tr>
<td>-d（default）</td>
<td>设定默认 ACL 权限。只对目录生效，指目录中新建立的文件拥有此默认权限</td>
</tr>
<tr>
<td>-k（remove-default）</td>
<td>删除默认 ACL 权限</td>
</tr>
<tr>
<td>-R（recursive）</td>
<td>递归设定 ACL 权限。指设定的 ACL 权限会对目录下的所有子文件生效</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">setfacl -m u:qv123:rx /project/</span><br></pre></td></tr></table></figure>
</li>
<li><p>删除acl权限：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">删除指定用户的 ACL 权限</span></span><br><span class="line">setfacl -x u:用户名 文件名</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">删除指定用户组的 ACL 权限</span></span><br><span class="line">setfacl -x g:组名 文件名</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">删除文件的所有 ACL 权限</span></span><br><span class="line">setfacl -b 文件名</span><br></pre></td></tr></table></figure>
</li>
<li><p>最大有效权限 mask：</p>
<ul>
<li><p>给用户或用户组设定 ACL 权限其实并不是真正我们设定的权限，是与 mask 的权限“相与”之后的权限才是用户的真正权限，一般默认mask权限都是rwx，与我们所设定的权限相与就是我们设定的权限</p>
</li>
<li><p>查看 mask 的权限：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">getfacl 文件名</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
<h2 id="4-权限掩码umask："><a href="#4-权限掩码umask：" class="headerlink" title="4.权限掩码umask："></a>4.权限掩码umask：</h2><ul>
<li><p><strong>设置新建文件或目录的默认权限</strong></p>
<ul>
<li><p>在Linux系统中，当用户创建一个新的文件或目录时，系统都会为新建的文件或目录分配默认的权限，该默认权限与umask值有关，其具体关系是：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">新建文件的默认权限=0666-umask值</span><br><span class="line">新建目录的默认权限=0777-umask值</span><br></pre></td></tr></table></figure>
</li>
<li><p>umask：查看默认umask值</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]# umask  //查看当前用户的umask权限</span><br><span class="line">0022</span><br><span class="line">[root@localhost ~]# touch file800</span><br><span class="line">[root@localhost ~]# mkdir dir800</span><br><span class="line">[root@localhost ~]# ll -d dir800 file800</span><br><span class="line">drwxr-xr-x. 2 root root 4096 3月 11 19:40 dir800</span><br><span class="line">-rw-r--r--. 1 root root 0 3月 11 19:40 file800</span><br></pre></td></tr></table></figure>
</li>
<li><p>umask [num]：修改shell umask值（临时）</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]# umask 000</span><br><span class="line">[root@localhost ~]# mkdir dir900</span><br><span class="line">[root@localhost ~]# touch file900</span><br><span class="line">[root@localhost ~]# ll -d dir900 file900</span><br><span class="line">drwxrwxrwx. 2 root root 4096 3月 11 19:44 dir900</span><br><span class="line">-rw-rw-rw-. 1 root root 0 3月 11 19:44 file900</span><br></pre></td></tr></table></figure>
</li>
<li><p>修改shell umask值（永久）</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]# vim /etc/profile</span><br><span class="line">if [ $UID -gt 199 ] &amp;&amp; [ &quot;`id -gn`&quot; = &quot;`id -un`&quot; ]; then</span><br><span class="line">umask 002</span><br><span class="line">else</span><br><span class="line">umask 022</span><br><span class="line">fi</span><br><span class="line">[root@localhost ~]# source /etc/profile //立即在当前shell中生效</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
<h1 id="10-管理Linux的联网："><a href="#10-管理Linux的联网：" class="headerlink" title="10.管理Linux的联网："></a>10.管理Linux的联网：</h1><h2 id="1-配置网路："><a href="#1-配置网路：" class="headerlink" title="1.配置网路："></a>1.配置网路：</h2><ul>
<li><p>ip命令：使用ip命令配置临时生效的网络连接：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@master ~]# ip -4 addr add 192.168.168.16/24 dev ens160</span><br></pre></td></tr></table></figure>
</li>
<li><h3 id="nmcli命令行工具："><a href="#nmcli命令行工具：" class="headerlink" title="nmcli命令行工具："></a>nmcli命令行工具：</h3><ul>
<li><p>查看网卡设备:</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@kongd ~]# nmcli device</span><br><span class="line">DEVICE TYPE     STATE     CONNECTION</span><br><span class="line">ens160 ethernet connected ens160</span><br><span class="line">lo     loopback unmanaged --</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">connected：已被NM管理，并且当前有活跃的connection</span><br><span class="line">disconnected：已被NM管理，但是当前没有活跃的connection</span><br><span class="line">unmanaged：未被NM管理</span><br><span class="line">unavailable：不可用，NM无法管理，通常出现于网卡为down的时候</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看配置文件：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">cat /etc/sysconfig/network-scripts/ifcfg-[会话名]</span><br><span class="line">TYPE=Ethernet</span><br><span class="line">PROXY_METHOD=none</span><br><span class="line">BROWSER_ONLY=no</span><br><span class="line">BOOTPROTO=none       # IP地址获取方式</span><br><span class="line">IPADDR=192.168.1.100     # ip地址</span><br><span class="line">PREFIX=24       # 掩码</span><br><span class="line">IPADDR1=192.168.1.101</span><br><span class="line">PREFIX1=32</span><br><span class="line">GATEWAY=192.168.1.254</span><br><span class="line">DNS1=8.8.8.8</span><br><span class="line">DNS2=4.4.4.4</span><br><span class="line">DEFROUTE=yes</span><br><span class="line">IPV4_FAILURE_FATAL=no</span><br><span class="line">IPV6INIT=yes</span><br><span class="line">IPV6_AUTOCONF=yes</span><br><span class="line">IPV6_DEFROUTE=yes</span><br><span class="line">IPV6_FAILURE_FATAL=no</span><br><span class="line">IPV6_ADDR_GEN_MODE=stable-privacy</span><br><span class="line">NAME=ethX-test      # 会话的名称</span><br><span class="line">UUID=9a10ad89-437c-4caa-949c-a394a6d28c8d     # 进程唯一标识</span><br><span class="line">DEVICE=ethX         # 网卡名</span><br><span class="line">ONBOOT=yes          # 开机自启</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看dns配置文件：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cat /etc/resolv.conf</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看相应的会话:</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[root@qv123 ~]# nmcli connection</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">NAME会话名，DEVICE网卡名</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">一个网卡可以有多个会话，但同时只能有一个会话生效；一个会话可以配置多个IP地址</span></span><br><span class="line">NAME    UUID                                  TYPE      DEVICE </span><br><span class="line">ens160  9849f46a-faae-4433-abe1-2facd03f6370  ethernet  ens160 </span><br><span class="line">virbr0  df202f4e-aedc-4d44-9e4b-0a15ea303d35  bridge    virbr0</span><br></pre></td></tr></table></figure>

<ul>
<li>nmcli connection的选项</li>
</ul>
<table>
<thead>
<tr>
<th>选项</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>modify</td>
<td>配置已存在的会话</td>
</tr>
<tr>
<td>add</td>
<td>新建会话</td>
</tr>
<tr>
<td>up</td>
<td>连接会话</td>
</tr>
<tr>
<td>down</td>
<td>断开会话</td>
</tr>
<tr>
<td>delete</td>
<td>删除会话</td>
</tr>
</tbody></table>
</li>
<li><p><strong>配置已存在会话的网卡的ip地址</strong>（非交互式）</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">先将dhcp变为none</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">manual：手工的，auto:获取方式为dhcp</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">autoconnect <span class="built_in">yes</span>：开机自动连接这个会话</span></span><br><span class="line">[root@kongd ~]# nmcli connection modify [会话名] ipv4.method manual ipv4.addresses 192.168.73.149/24 ipv4.gateway 192.168.73.2 ipv4.dns 180.76.76.76 autoconnect yes</span><br><span class="line">[root@kongd ~]# nmcli c up ens160    # 重新加载配置文件(最好选择重启系统)</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>添加新的会话</strong>：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nmcli c add type ethernet con-name [会话名] ifname [网卡名] ipv4.addresses &#x27;192.168.73.240/24,192.168.73.241/24&#x27; ipv4.gateway &#x27;192.168.73.2&#x27; ipv4.dns &#x27;180.76.76.76&#x27; ipv4.method manual autoconnect yes</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">type ethernet：创建连接时候必须指定类型，类型有很多，可以通过 nmcli c add type -h 看到，这里指定为ethernet。</span><br><span class="line">con-name ethX-test：ethX-test表示连接（connection）的名字，这个名字可以任意定义，无需和网卡名相同</span><br><span class="line">ifname ethX：ethX表示网卡名，这个ethX必须是在 nmcli d 里能看到的网卡的名字</span><br><span class="line">ipv4.method：默认为auto，对应网卡配置文件里的BOOTPROTO=dhcp；</span><br><span class="line">ipv4.method manual，对应网卡配置文件里的BOOTPROTO=none，即只有静态ip</span><br><span class="line">autoconnect yes：对应网卡配置文件里的ONBOOT=yes</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>连接、断开、删除会话</strong>:</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">连接会话</span></span><br><span class="line">[root@kongd ~]# nmcli c up [会话名]</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">断开会话</span></span><br><span class="line">[root@kongd ~]# nmcli c down [会话名]</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">删除会话</span></span><br><span class="line">[root@kongd ~]# nmcli c delete [会话名]	</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><h3 id="使用nmtui配置"><a href="#使用nmtui配置" class="headerlink" title="使用nmtui配置"></a>使用nmtui配置</h3></li>
</ul>
<h2 id="2-网络测试命令"><a href="#2-网络测试命令" class="headerlink" title="2.网络测试命令:"></a>2.网络测试命令:</h2><ul>
<li><p>使用ping命令测试网络的连通性：ping [选项] &lt;目标主机名或IP地址&gt;</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-c 数字</td>
<td>用于设定本命令发出的ICMP消息包的数量，若无此选项，则会无限次发送消息包直到用户按【Ctrl+C】组合键才终止命令</td>
</tr>
<tr>
<td>-s 字节数</td>
<td>设置ping命令发出的消息包的大小，默认发送的测试数据大小为56字节；自动添加8字节的ICMP协议头后,显示的是64字节；再添加20字节的IP协议头，则显示的为84字节。最大设置</td>
</tr>
<tr>
<td>-i 时间间隔</td>
<td>设定前后两次发送ICMP消息包之间的时间间隔，无此选项时，默认时间间隔为1秒。为了保障本机和目标主机的安全，一般不要小于0.2秒</td>
</tr>
<tr>
<td>-t</td>
<td>设置存活时间TTL(Time To Live)</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ping -c 2 www.baidu.com</span><br></pre></td></tr></table></figure>
</li>
<li><p>使用tracepath命令跟踪并显示网络路径：tracepath [选项] &lt;目标主机名或目标IP地址&gt;</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-n（）</td>
<td>对沿途各主机节点,，仅仅获取并输出IP地址，不在每个IP 地址的节点设备上通过DNS查找其主</td>
</tr>
<tr>
<td>-b（both）</td>
<td>对沿途各主机节点同时显示IP地址和主机名</td>
</tr>
<tr>
<td>-l（length）</td>
<td>设置初始的数据包的大小</td>
</tr>
<tr>
<td>-p（port）</td>
<td>设置UDP传输协议的端口(缺省为33434)</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@zhanglin network-scripts]# tracepath -b www.baidu.com</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@zhanglin network-scripts]# tracepath -l 1024 8.130.17.95</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@zhanglin network-scripts]# tracepath -p 22 8.130.17.95</span><br></pre></td></tr></table></figure>
</li>
<li><p>traceroute (Windows 系统下是tracert) 命令利用ICMP 协议定位您的计算机和目标计算机之间的所有路由器</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">traceroute (Windows 系统下是tracert) 命令利用ICMP 协议定位您的计算机和目标计算机之间的所有路由器</span></span><br><span class="line">traceroute -I www.baidu.com     # -I表示使用ICMP协议</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="3-通过域名访问主机："><a href="#3-通过域名访问主机：" class="headerlink" title="3.通过域名访问主机："></a>3.通过域名访问主机：</h2><ol>
<li><p>配置静态解析，通过&#x2F;etc&#x2F;hosts文件实现域名解析</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[root@master ~]# cat /etc/hosts</span><br><span class="line">127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4</span><br><span class="line">::1 localhost localhost.localdomain localhost6 localhost6.localdomain6</span><br><span class="line">192.168.168.11 master</span><br><span class="line">[root@master ~]# ping master</span><br><span class="line">PING master (192.168.168.11) 56(84) bytes of data.</span><br><span class="line">64 bytes from master (192.168.168.11): icmp_seq=1 ttl=64 time=0.131 ms</span><br></pre></td></tr></table></figure>
</li>
<li><p>通过&#x2F;etc&#x2F;resolv.conf文件指派域名解析服务器的地址，由dns服务器做域名解析</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[root@master ~]# cat /etc/resolv.conf</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">Generated by NetworkManager</span></span><br><span class="line">nameserver 192.168.168.2</span><br><span class="line">[root@master ~]# host www.baidu.com</span><br><span class="line">www.baidu.com is an alias for www.a.shifen.com.</span><br><span class="line">www.a.shifen.com has address 110.242.68.3</span><br><span class="line">www.a.shifen.com has address 110.242.68.4</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">当通过域名访问服务器的时候，其默认解析顺序为hosts文件、resolv.conf文件中的DNS服务器。其响应的先后顺序可在文件/etc/nsswitch.conf中设置。</span></span><br></pre></td></tr></table></figure></li>
</ol>
<h1 id="11-从网站下载文件"><a href="#11-从网站下载文件" class="headerlink" title="11.从网站下载文件:"></a>11.从网站下载文件:</h1><ol>
<li><p>wget命令用于在终端命令行里下载网络文件，英文全称为：“web get”，语法格式为： wget [选项] 网址</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-P（prefix）</td>
<td>下载到指定目录</td>
</tr>
<tr>
<td>-t（tries）</td>
<td>最大尝试次数</td>
</tr>
<tr>
<td>-b（backgroud）</td>
<td>后台下载模式</td>
</tr>
<tr>
<td>-c（continue）</td>
<td>断点续传s</td>
</tr>
<tr>
<td>-p（page）</td>
<td>下载页面内所有资源，包括图片、视频等</td>
</tr>
<tr>
<td>-r（recursive）</td>
<td>递归下载</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wget http://rpmfind.net/linux/epel/8/Everything/x86_64/Packages/s/sl-5.02-1.el8.x86_64.rpm</span><br></pre></td></tr></table></figure>
</li>
<li><p>curl命令是一个网络工具，其主要作用是通过http、https、ftp等方式下载&#x2F;上传文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl www.baidu.com -o index.html</span><br></pre></td></tr></table></figure></li>
</ol>
<h1 id="12-软件包管理RPM和YUM数据库："><a href="#12-软件包管理RPM和YUM数据库：" class="headerlink" title="12.软件包管理RPM和YUM数据库："></a>12.软件包管理RPM和YUM数据库：</h1><h2 id="1-软件包管理RPM："><a href="#1-软件包管理RPM：" class="headerlink" title="1.软件包管理RPM："></a>1.软件包管理RPM：</h2><ul>
<li><p>RPM是红帽包管理(Redhat Package Manager)的缩写</p>
<ul>
<li><p>由Red Hat公司提出的一种软件包管理标准</p>
</li>
<li><p>是Linux各发行版中应用最广泛的软件包格式之一（还有debian的发行版deb安装包）</p>
</li>
<li><p>RPM功能通过rpm命令使用不同参数来实现</p>
</li>
</ul>
</li>
<li><p>rmp的作用类似于windows上的电脑管家中 “软件管理” ，主要作用是对Linux服务器上的软件包进行对应管理操作，管理分为：查询，卸载，安装。</p>
</li>
<li><p>RPM软件包的典型命名格式：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">软件名-版本号-发行号.操作系统版本.硬件平台的类型.rpm</span><br><span class="line">zsh  -5.0.2 -14   .el7        .x86_64       .rpm</span><br></pre></td></tr></table></figure>
</li>
<li><p>rpm包相关网站<a target="_blank" rel="noopener" href="http://rpmfind.net/%EF%BC%8Chttp://rpm.pbone.net/">http://rpmfind.net/，http://rpm.pbone.net/</a></p>
</li>
<li><h3 id="rpm安装"><a href="#rpm安装" class="headerlink" title="rpm安装"></a>rpm安装</h3><table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-i（install）</td>
<td>安装软件包</td>
</tr>
<tr>
<td>–nodeps</td>
<td>不验证软件包依赖</td>
</tr>
<tr>
<td>-v（verbose）</td>
<td>提供更多的详细信息输出</td>
</tr>
<tr>
<td>-h（hash）</td>
<td>软件包安装的时候列出哈希标记</td>
</tr>
<tr>
<td>-U（upgrade）</td>
<td>软件包升级</td>
</tr>
<tr>
<td>-e（erase）</td>
<td>软件包卸载</td>
</tr>
</tbody></table>
<ul>
<li><p>通过本地光盘镜像文件安装rpm包</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">安装tree包</span></span><br><span class="line">[root@master Packages]# rpm -ivh tree-1.7.0-15.el8.x86_64.rpm</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">卸载tree包</span></span><br><span class="line">[root@master Packages]# rpm -evh tree</span><br></pre></td></tr></table></figure>
</li>
<li><p>从网上下载rpm包并安装：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wget http://rpmfind.net/linux/epel/8/Everything/x86_64/Packages/s/sl-5.02-1.el8.x86_64.rpm</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><h3 id="rpm查询：（rpm-–q-常与下面参数组合使用）"><a href="#rpm查询：（rpm-–q-常与下面参数组合使用）" class="headerlink" title="rpm查询：（rpm –q 常与下面参数组合使用）"></a>rpm查询：（rpm –q 常与下面参数组合使用）</h3><table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-a（all）</td>
<td>查询所有已安装的软件包</td>
</tr>
<tr>
<td>-l（list）</td>
<td>显示已安装软件包的相关文件列表和信息</td>
</tr>
<tr>
<td>-f（file）</td>
<td>查询文件所属软件包</td>
</tr>
<tr>
<td>-i（install）</td>
<td>显示已经安装的rpm软件包信息</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm -qa   # 查询所有已经安装的包</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查询某个包有没有安装（包名不能写错）</span></span><br><span class="line">[root@master Packages]# rpm -q httpd</span><br><span class="line">httpd-2.4.37-43.module+el8.5.0+747+83fae388.3.x86_64</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查询安装该包后会产生哪些文件</span></span><br><span class="line">[root@master Packages]# rpm -ql tree</span><br><span class="line">/usr/bin/tree</span><br><span class="line">/usr/lib/.build-id</span><br><span class="line">/usr/lib/.build-id/47</span><br><span class="line">/usr/lib/.build-id/47/6e749c56abc75d25e3bc5c29e83507a605fd53</span><br><span class="line">/usr/share/doc/tree</span><br><span class="line">/usr/share/doc/tree/LICENSE</span><br><span class="line">/usr/share/doc/tree/README</span><br><span class="line">/usr/share/man/man1/tree.1.gz</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查询该文件由哪个软件包产生</span></span><br><span class="line">[root@master Packages]# rpm -qf /usr/bin/ls</span><br><span class="line">coreutils-8.30-12.el8.x86_64</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="2-YUM："><a href="#2-YUM：" class="headerlink" title="2.YUM："></a>2.YUM：</h2><ul>
<li><p>YUM (Yellow dog Updater，Modified) ，RHEL8中默认使用的软件批量管理工具由原版本的yum换成了速度更快的dnf（DNF &#x3D; Dandified YUM）</p>
</li>
<li><p>YUM&#x2F;DNF 功能</p>
<ul>
<li>在线下载、 安装、 卸载、 升级rpm软件包</li>
<li>自动查找并解决rpm包之间的依赖关系，一次性安装所有具有依赖关系的rpm包，而无需管理员逐个、 手工地去安装每一个rpm包</li>
</ul>
</li>
<li><p>如何实现yum&#x2F;DNF安装</p>
<ul>
<li>系统会去读取 &#x2F;etc&#x2F;yum.repos.d&#x2F; 目录下的 .repo 结尾的文件，从该文件中读取以下内容实现装包</li>
<li>包含各种rpm安装文件的软件仓库（rhel8有两个仓库，rhel7只有一个仓库）<ul>
<li>BaseOS存储库：提供一套核心的底层操作系统功能，为基础软件安装库</li>
<li>AppStream存储库：包括额外的用户空间应用程序、运行时语言和数据库</li>
</ul>
</li>
</ul>
</li>
<li><p>配置 .repo 文件，即yum源</p>
<ul>
<li><p>建立本地源：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">[root@kongd ~]# mkdir /media/cdrom</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">将本地光盘挂载至本地目录/media/cdrom下</span></span><br><span class="line">[root@kongd ~]# mount /dev/cdrom /media/cdrom</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">将/etc/yum.repos.d/目录下的文件清空，然后创建一个repo</span></span><br><span class="line">[root@kongd ~]# vim /etc/yum.repos.d/redhat.repo</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">加入以下内容</span></span><br><span class="line">[RHEL8-BaseOS]</span><br><span class="line">name=RHEL8-BaseOS</span><br><span class="line">baseurl=file:///media/cdrom/BaseOS</span><br><span class="line">gpgcheck=0</span><br><span class="line"></span><br><span class="line">[RHEL8-Appstream]</span><br><span class="line">name=RHEL8-Appstream</span><br><span class="line">baseurl=file:///media/cdrom/AppStream</span><br><span class="line">gpgcheck=0</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">验证是否成功</span></span><br><span class="line">[root@kongd ~]# yum repolist</span><br><span class="line">Failed to set locale, defaulting to C.UTF-8</span><br><span class="line">Updating Subscription Management repositories.</span><br><span class="line">Unable to read consumer identity</span><br><span class="line"></span><br><span class="line">This system is not registered with an entitlement server. You can use subscription-manager to register.</span><br><span class="line"></span><br><span class="line">repo id                                                     repo name</span><br><span class="line">RHEL8-Appstream                                             RHEL8-Appstream</span><br><span class="line">RHEL8-BaseOS                                                RHEL8-BaseOS</span><br><span class="line">[root@master ~]# yum install bind-utils -y</span><br><span class="line">Failed to set locale, defaulting to C.UTF-8</span><br><span class="line">Updating Subscription Management repositories.</span><br><span class="line">Unable to read consumer identity</span><br><span class="line"></span><br><span class="line">This system is not registered with an entitlement server. You can use subscription-manager to register.</span><br><span class="line"></span><br><span class="line">RHEL8-BaseOS                                                                             12 MB/s | 2.4 MB     00:00    </span><br><span class="line">RHEL8-Appstream                                                                          18 MB/s | 7.2 MB     00:00    </span><br><span class="line">Last metadata expiration check: 0:00:02 ago on Mon Oct 17 12:02:48 2022.</span><br><span class="line">Package bind-utils-32:9.11.26-6.el8.x86_64 is already installed.</span><br><span class="line">Dependencies resolved.</span><br><span class="line">Nothing to do.</span><br><span class="line">Complete!</span><br></pre></td></tr></table></figure>
</li>
<li><p>建立网络源:</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">阿里云网络源，aliyun的镜像站点为https://mirrors.aliyun.com/</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">清华源镜像站点为https://mirrors.tuna.tsinghua.edu.cn/</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">中国科技大学镜像站点https://mirrors.ustc.edu.cn/</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">网易开源镜像站http://mirrors.163.com/</span></span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">直接通过网络下载配置文件</span></span><br><span class="line">wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">[root@master ~]# cat /etc/redhat-release</span><br><span class="line">Rocky Linux release 8.5 (Green Obsidian)</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">注：此处先查看自己的发行版本信息，选择相应的仓库。</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">仓库文件可以自己写也可以从aliyun网站下载</span></span><br><span class="line">[root@master ~]# vim /etc/yum.repos.d/aliyun.repo </span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">写入以下信息</span></span><br><span class="line">[appstream]</span><br><span class="line">name=appstream</span><br><span class="line">baseurl=https://mirrors.aliyun.com/rockylinux/8.5/AppStream/x86_64/os/</span><br><span class="line">gpgcheck=0</span><br><span class="line">[baseos]</span><br><span class="line">name=baseos</span><br><span class="line">baseurl=https://mirrors.aliyun.com/rockylinux/8.5/BaseOS/x86_64/os/</span><br><span class="line">gpgcheck=0</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><h3 id="查看包、包组相关信息："><a href="#查看包、包组相关信息：" class="headerlink" title="查看包、包组相关信息："></a>查看包、包组相关信息：</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum repolist [all]   # 查看系统中yum资源库配置信息</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum list all   # 列出仓库里所有可安装的软件包</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum list installed [包名]   # 列出己经安装的所有的或指定的rpm包(包名中可使用匹配符)</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum info 包名   # 查看指定软件包的详细信息</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum grouplist   # 查看仓库里而所有包组</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum groupinfo 包组名   # 查看指定包组里而的详细信息</span><br></pre></td></tr></table></figure>
</li>
<li><h3 id="安装、更新包和包组："><a href="#安装、更新包和包组：" class="headerlink" title="安装、更新包和包组："></a>安装、更新包和包组：</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">yum install [-y] 包名   # 安装指定的软件包，-y则在工作过程中需要使用者响应， 这个选个参数可以直接回答yes</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">如果安装出现错误incorrect checksum，挂载/dev/cdrom</span></span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum update [-y] 包名    # 升级指定的软件包或主机中所有已安装的软件包</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum groupinstall 包组名   # 安装指定包组里面的所有包</span><br></pre></td></tr></table></figure>
</li>
<li><h3 id="卸载软件包："><a href="#卸载软件包：" class="headerlink" title="卸载软件包："></a>卸载软件包：</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum remove [-y] 包名 # 卸载已经安装在系统中的指定的软件包</span><br></pre></td></tr></table></figure>
</li>
<li><h3 id="搜索文件："><a href="#搜索文件：" class="headerlink" title="搜索文件："></a>搜索文件：</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum provides 文件名  # 查找指定的文件属于哪个包</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum whatprovides /etc/fstab   # 查看这个文件是由那个包提供的</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum search 模糊包名  # 查看模糊包名的软件包</span><br></pre></td></tr></table></figure>
</li>
<li><h3 id="清空缓存："><a href="#清空缓存：" class="headerlink" title="清空缓存："></a>清空缓存：</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum clean packages all   # 清除下载到本机的指定的软件包或所有软件包的yum源缓存</span><br></pre></td></tr></table></figure>
</li>
<li><p>RHEL8相应地在yum命令下，增加了一个module子命令。多了个模块（module）、模块下多了个序列（Stream）、序列下多了个组合（profile）</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum module list  # 列出模块</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum module list [模块名]   # 列出指定模块</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="3-源代码编译："><a href="#3-源代码编译：" class="headerlink" title="3.源代码编译："></a>3.源代码编译：</h2><h2 id="4-进程简介"><a href="#4-进程简介" class="headerlink" title="4.进程简介"></a>4.进程简介</h2><ul>
<li><p><strong>程序</strong>： 二进制文件，文件存储在磁盘中，例如&#x2F;usr&#x2F;bin&#x2F;目录下</p>
</li>
<li><p><strong>进程</strong>：进程是已启动的可执行程序的运行实例。</p>
<ul>
<li>进程和程序并不是一一对应的关系，相同的程序运行在不同的数据集上就是不同的进程</li>
<li>进程还具有并发性和交往性，而程序却是封闭的</li>
</ul>
</li>
<li><p><strong>线程：</strong>是操作系统能够进行运算调度的最小单位。它被包含在进程之中，是进程中的实际运作单位。一条线程指的是进程中一个单一顺序的控制流，一个进程中可以并发多个线程，每条线程并行执行不同的任务。</p>
<ul>
<li>一个进程可以拥有多个线程，而一个线程同时只能被一个进程所拥有</li>
<li>线程不能单独执行，但是每一个线程都有程序的入口、执行序列以及程序出口，它必须组成进程才能被执行</li>
</ul>
</li>
<li><p>进程分类</p>
</li>
</ul>
<h2 id="5-查看进程："><a href="#5-查看进程：" class="headerlink" title="5.查看进程："></a>5.查看进程：</h2><ul>
<li><h3 id="ps命令查看进程"><a href="#ps命令查看进程" class="headerlink" title="ps命令查看进程:"></a>ps命令查看进程:</h3><table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-a（all）</td>
<td>显示所有用户的进程</td>
</tr>
<tr>
<td>-u（user）</td>
<td>显示用户名和启动时间</td>
</tr>
<tr>
<td>-x（）</td>
<td>显示 没有控制终端的进程</td>
</tr>
<tr>
<td>-e（）</td>
<td>显示所有进程，包括没有控制终端的进程</td>
</tr>
<tr>
<td>-l（long）</td>
<td>长格式显示</td>
</tr>
<tr>
<td>-w（width）</td>
<td>宽行显示，可以使用多个 w 进行加宽显示</td>
</tr>
<tr>
<td>-f（full）</td>
<td>做一个更完整的输出</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查看当前用户的进程</span></span><br><span class="line">[root@localhost ~]# ps -l</span><br><span class="line">F S UID PID   PPID  C PRI NI ADDR SZ WCHAN TTY   TIME     CMD</span><br><span class="line">4 S 0   42097 42091 0 80  0 - 29040  wait  pts/0 00:00:00 bash</span><br><span class="line">0 R 0   43256 42097 0 80  0 - 34857  -     pts/0 00:00:00 ps</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查看所有用户执行的进程的详细信息</span></span><br><span class="line">[root@localhost ~]# ps -le</span><br><span class="line">F S UID PID PPID C PRI NI   ADDR SZ WCHAN TTY TIME     CMD</span><br><span class="line">4 S 0   1   0    0 80  0   - 44776 do_epo ?   00:00:01 systemd</span><br><span class="line">1 S 0   2   0    0 80  0   - 0     -      ?   00:00:00 kthreadd</span><br><span class="line">1 I 0   3   2    0 60  -20 - 0     -      ?   00:00:00 rcu_gp</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查看当前用户的进程</span></span><br><span class="line">[root@localhost ~]# ps -u</span><br><span class="line">USER PID  %CPU %MEM VSZ    RSS  TTY   STAT START TIME COMMAND</span><br><span class="line">root 1280 2.2  0.2  237304 5408 tty1  Ss+  15:54 0:00 -bash</span><br><span class="line">root 1415 0.1  0.2  237172 5092 pts/0 Ss   15:55 0:00 -bash</span><br><span class="line">root 1452 0.0  0.2  268484 4008 pts/0 R+   15:55 0:00 ps -u</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">#查看进程树</span><br><span class="line">[root@localhost ~]# pstree</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查看指定进程的PID</span></span><br><span class="line">[root@localhost ~]# ps aux | grep sshd</span><br><span class="line">root     752  0.0  0.3   92288   6976 ?      Ss    15:46     0:00</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查看指定进程的PID</span></span><br><span class="line">[root@localhost ~]# pgrep -l sshd</span><br><span class="line">752 sshd</span><br><span class="line">1408 sshd</span><br><span class="line">11.5.2 top命令查看进程</span><br><span class="line">语法： top [-d 数字] | [-bnp]</span><br><span class="line">top的输出可以分为统计信息区和进程信息区两个部分，即前5行为统计信息区，后面为进程信息区。</span><br><span class="line">统计信息区</span><br><span class="line">1412 sshd</span><br><span class="line">1413 sshd</span><br><span class="line">1438 sshd</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查看指定进程的PID</span></span><br><span class="line">[root@localhost ~]# pidof sshd</span><br><span class="line">1438 1413 1412 1408 752</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">查看系统中所有包含其他使用者的进程</span></span><br><span class="line">ps -aux</span><br></pre></td></tr></table></figure>


</li>
<li><h3 id="top命令查看进程：（top-d-数字-bnp-）（动态查看）"><a href="#top命令查看进程：（top-d-数字-bnp-）（动态查看）" class="headerlink" title="top命令查看进程：（top [-d 数字] | [-bnp]）（动态查看）"></a>top命令查看进程：（top [-d 数字] | [-bnp]）（动态查看）</h3><table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-d</td>
<td>后面可以接秒数，就是整个进程界面更新的秒数，默认是5秒</td>
</tr>
<tr>
<td>-b</td>
<td>以批次的方式执行top，还有更多的参数可用。通常会搭配数据流重定向来将批处理的结果输出为文件</td>
</tr>
<tr>
<td>-n</td>
<td>与-b搭配，进行几次top的输出结果</td>
</tr>
<tr>
<td>-i</td>
<td>不显示闲置或者僵死的进程信息</td>
</tr>
<tr>
<td>-c</td>
<td>显示进程的整个命令路径，而不是只显示命令名称</td>
</tr>
<tr>
<td>-s</td>
<td>使top命令在安全模式下运行，此时top的交互式指令被取消，避免潜在危险</td>
</tr>
<tr>
<td>-p</td>
<td>指定某些个PID来进行查看检测</td>
</tr>
</tbody></table>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">top -d 1</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">top -d 1 -p 10126    # 查看指定进程的动态信息</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">top -d 1 -u apache   # 查看指定用户的进程</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="6-信号控制进程"><a href="#6-信号控制进程" class="headerlink" title="6.信号控制进程:"></a>6.信号控制进程:</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">kill -l     # 列出所有支持的信号</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">killall vim    # 给所有vim进程发送信号</span><br></pre></td></tr></table></figure>

<h2 id="7-作业控制"><a href="#7-作业控制" class="headerlink" title="7.作业控制:"></a>7.作业控制:</h2><ul>
<li><p>作业控制是一个命令行功能，允许一个shell 实例来运行和管理多个命令。如果没有作业控制，父进程fork()一个子进程后，将sleeping，直到子进程退出。使用作业控制，可以选择性暂停，恢复，以及异步运行命令，让 shell 可以在子进程运行期间返回接受其他命令</p>
</li>
<li><p><strong>foreground:</strong> <strong>前台进程</strong>是在终端中运行的命令，该终端为进程的控制终端。前台进程接收键盘产生的输入和信号，并允许从终端读取或写入到终端。</p>
</li>
<li><p><strong>background:</strong> <strong>后台进程</strong>没有控制终端，它不需要与终端交互。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]# [命令] &amp;                 #运行程序（时），让其在后台执</span><br><span class="line"></span><br><span class="line">[root@localhost ~]# sleep 4000                   #ctrl+z可以将前台的任务放到</span><br><span class="line">后台中暂停</span><br><span class="line">[2]+ Stopped sleep 4000</span><br><span class="line">[root@localhost ~]# ps aux |grep sleep</span><br><span class="line">root 8895 0.0 0.0 100900 556 pts/0 S 12:13 0:00 sleep 3000</span><br><span class="line">root 8896 0.0 0.0 100900 556 pts/0 T 12:13 0:00 sleep 4000</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查看当前终端放在后台的进程（ <span class="built_in">jobs</span> ）</span></span><br><span class="line">[root@localhost ~]# jobs</span><br><span class="line">[1]- Running sleep 3000 &amp;</span><br><span class="line">[2]+ Stopped sleep 4000</span><br><span class="line">+表示最近被放到后台的工作，-表示最近第二个被放到后台中的工作，超过第三个就不会有+/-符号存在了</span><br><span class="line">[root@localhost ~]# bg %2                        #让作业2在后台继续运行</span><br><span class="line">[root@localhost ~]# fg %1                          #将作业1调回到前台</span><br><span class="line">[root@localhost ~]# kill %1               #kill 1，终止工作号为1的进程</span><br></pre></td></tr></table></figure></li>
</ul>
<h1 id="13-磁盘管理"><a href="#13-磁盘管理" class="headerlink" title="13.磁盘管理:"></a>13.磁盘管理:</h1><h2 id="1-维护基本存储空间"><a href="#1-维护基本存储空间" class="headerlink" title="1.维护基本存储空间:"></a>1.维护基本存储空间:</h2><ul>
<li>在创建Linux分区时，一定要创建<strong>SWAP&#x2F;根分区</strong>两个分区</li>
</ul>
<h3 id="1-分区的两种格式"><a href="#1-分区的两种格式" class="headerlink" title="1.分区的两种格式:"></a>1.分区的两种格式:</h3><ul>
<li><h3 id="MBR分区"><a href="#MBR分区" class="headerlink" title="MBR分区:"></a>MBR分区:</h3><ul>
<li>MBR(Master Boot Record，主引导记录)是传统的分区机制，使用BIOS引导PC设备，寻址空间只有32bit长</li>
<li>分区空间最大支持2.2TB</li>
<li>支持的分区数量：4个主分区或者3个主分区1个扩展分区</li>
<li>为什么MBR最多只能有4个主分区：因为分区表占据64个字节，其中每个分区的信息占用16个字节，分区表里面可以记录四个分区信息描述</li>
<li>MBR分区类型：<ul>
<li><strong>一块硬盘最多有3个分区（扩展分区+主分区），并且扩展分区最多一个</strong></li>
<li>主分区（primary partition)：<ul>
<li>一块硬盘最多4个主分区，主分区不可以再进行二次分区</li>
<li>主分区可以直接建立文件系统，存放数据</li>
<li>可以用来引导、启动操作系统</li>
</ul>
</li>
<li>扩展分区（extended partition)<ul>
<li>一块硬盘最多一个扩展分区</li>
<li>不能创建文件系统</li>
<li>可以划分逻辑分区</li>
</ul>
</li>
<li>逻辑分区(logical partition)：<ul>
<li>可以创建文件系统，存放数据；</li>
<li>逻辑分区的数量没有限制</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><h3 id="GPT分区"><a href="#GPT分区" class="headerlink" title="GPT分区:"></a>GPT分区:</h3><ul>
<li>GPT(GUID Partition Table,全局唯一标识分区表)是一种比MBR分区更先进、更灵活的磁盘分区模式</li>
<li>在默认情况下,GPT<strong>最多可支持128个分区</strong></li>
<li>支持大于2.2TB的总容量及<strong>大于2.2TB的分区</strong>，最大支持18EB(1EB&#x3D;1024PB,1PB&#x3D;1024TB,1TB&#x3D;1024GB)</li>
<li>GPT分区表自带备份</li>
<li>向后兼容MBR，<strong>GPT分区表上包含保护性的MBR区域</strong></li>
</ul>
</li>
</ul>
<h3 id="2-查看磁盘信息（块设备）"><a href="#2-查看磁盘信息（块设备）" class="headerlink" title="2. 查看磁盘信息（块设备）:"></a>2. 查看磁盘信息（块设备）:</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">[root@kongd ~]# lsblk</span><br><span class="line">NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINT</span><br><span class="line">sr0           11:0    1  6.6G 0  rom</span><br><span class="line">nvme0n1       259:0   0  20G  0  disk</span><br><span class="line">├─nvme0n1p1   259:1   0  1G   0  part /boot</span><br><span class="line">└─nvme0n1p2   259:2   0  19G  0  part</span><br><span class="line">├─rhel-root   253:0   0  17G  0  lvm /</span><br><span class="line">└─rhel-swap   253:1   0  2G   0  lvm [SWAP]</span><br><span class="line">nvme0n2       259:3   0  2G   0  disk</span><br></pre></td></tr></table></figure>

<p>不同接口的磁盘在linux中的设备文件名不同</p>
<img src="C:\Users\user\AppData\Roaming\Typora\typora-user-images\image-20221017164728990.png" alt="image-20221017164728990" style="zoom:50%;" />

<h3 id="3-使用fdisk管理分区"><a href="#3-使用fdisk管理分区" class="headerlink" title="3.使用fdisk管理分区:"></a>3.使用fdisk管理分区:</h3><ul>
<li><p>fdisk命令工具默认将磁盘划分为MBR格式的分区</p>
</li>
<li><p>命令： fdisk 设备名</p>
</li>
<li><p>fdisk命令以交互方式进行操作的，在菜单中选择相应功能键即可</p>
</li>
<li><p>进入分区后的指令：</p>
<table>
<thead>
<tr>
<th>指令</th>
<th>作用</th>
<th>指令</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>a</td>
<td>调整磁盘的启动分区</td>
<td>p（print）</td>
<td><strong>显示当前磁盘的分区信息</strong></td>
</tr>
<tr>
<td>d（delete）</td>
<td><strong>删除磁盘分区</strong></td>
<td>t（type）</td>
<td>更改分区类型</td>
</tr>
<tr>
<td>l（）</td>
<td>显示所有支持的分区类型</td>
<td>u（units）</td>
<td><strong>切换所显示的分区大小单位</strong></td>
</tr>
<tr>
<td>m（menu）</td>
<td><strong>查看所有指令的帮助信息</strong></td>
<td>n（new）</td>
<td><strong>创建新分区</strong></td>
</tr>
<tr>
<td>q（quit）</td>
<td>不保存更改,退出fdisk命令</td>
<td>w（wirter）</td>
<td>把修改写入磁盘分区表,然后退出fdisk命令</td>
</tr>
<tr>
<td>g（gpt）</td>
<td>新建一个空的GPT分区表</td>
<td>o（）</td>
<td>新建一个空的DOS分区表</td>
</tr>
</tbody></table>
</li>
<li><p>通过lsblk命令查看设备名：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">[root@qv123 ~]# lsblk</span><br><span class="line">NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT</span><br><span class="line">sr0            11:0    1 10.2G  0 rom  </span><br><span class="line">nvme0n1       259:0    0   20G  0 disk </span><br><span class="line">|-nvme0n1p1   259:1    0    1G  0 part /boot</span><br><span class="line">`-nvme0n1p2   259:2    0   19G  0 part </span><br><span class="line">  |-rhel-root 253:0    0   17G  0 lvm  /</span><br><span class="line">  `-rhel-swap 253:1    0    2G  0 lvm  [SWAP]</span><br><span class="line">nvme0n2       259:3    0   10G  0 disk</span><br></pre></td></tr></table></figure>
</li>
<li><p>使用fdisk命令，进入设备</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">fdisk /dev/设备名</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看帮助信息：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">Command (m for help): m         # 输入m可查看帮助信息</span><br><span class="line">Help:</span><br><span class="line">DOS (MBR)</span><br><span class="line">a toggle a bootable flag</span><br><span class="line">b edit nested BSD disklabel</span><br><span class="line">c toggle the dos compatibility flag</span><br><span class="line">Generic</span><br><span class="line">d delete a partition</span><br><span class="line">F list free unpartitioned space</span><br><span class="line">l list known partition types</span><br><span class="line">n add a new partition</span><br><span class="line">p print the partition table</span><br><span class="line">t change a partition type</span><br><span class="line">v verify the partition table</span><br><span class="line">i print information about a partition</span><br><span class="line">....</span><br></pre></td></tr></table></figure>
</li>
<li><p>创建分区：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">Command (m for help): n    # 输入n创建新分区</span><br><span class="line">Partition type</span><br><span class="line">	p primary (0 primary, 0 extended, 4 free)        # 输入p创建主分区</span><br><span class="line">	e extended (container for logical partitions)    # 输入e创建扩展分区</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">创建主分区</span></span><br><span class="line">Select (default p): p      # 输入p创建主分区</span><br><span class="line">Partition number (1-4, default 1): 1      # 选择主分区号，输入1表示第一个主分区</span><br><span class="line">First sector (2048-10485759, default 2048):    # 直接按回车从当前第2048个扇区开始</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">分区</span></span><br><span class="line">Last sector, +sectors or +size&#123;K,M,G,T,P&#125; (2048-10485759, default 10485759):+300M     # 设置第一个分区为300M</span><br><span class="line">Created a new partition 1 of type &#x27;Linux&#x27; and of size 300 MiB.</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">创建扩展分区</span></span><br><span class="line">Command (m for help): n     # 输入n创建新分区</span><br><span class="line">Partition type</span><br><span class="line">p primary (1 primary, 0 extended, 3 free)</span><br><span class="line">e extended (container for logical partitions)</span><br><span class="line">Select (default p): e       # 输入e创建扩展分区</span><br><span class="line">Partition number (2-4, default 2): 2      # 选择分区号，输入2表示第二个分区</span><br><span class="line">First sector (616448-10485759, default 616448):      # 直接按回车从当前第616448个扇区开始分区</span><br><span class="line">Last sector, +sectors or +size&#123;K,M,G,T,P&#125; (616448-10485759, default 10485759):+500M   # 添加一个500M的分区</span><br><span class="line">Created a new partition 2 of type &#x27;Extended&#x27; and of size 500 MiB.</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看分区信息：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">Command (m for help): p</span><br><span class="line">Disk /dev/nvme0n2: 10 GiB, 10737418240 bytes, 20971520 sectors</span><br><span class="line">Units: sectors of 1 * 512 = 512 bytes</span><br><span class="line">Sector size (logical/physical): 512 bytes / 512 bytes</span><br><span class="line">I/O size (minimum/optimal): 512 bytes / 512 bytes</span><br><span class="line">Disklabel type: dos</span><br><span class="line">Disk identifier: 0x2b5ee117</span><br><span class="line"></span><br><span class="line">Device         Boot  Start     End Sectors  Size Id Type</span><br><span class="line">/dev/nvme0n2p1        2048  616447  614400  300M 83 Linux</span><br><span class="line">/dev/nvme0n2p2      616448 1640447 1024000  500M 83 L</span><br></pre></td></tr></table></figure>
</li>
<li><p>删除分区：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Command (m for help): d #输入d删除分区</span><br><span class="line">Partition number (1,2, default 2): 2 #输入2，选择需要删除的是第二个分区</span><br><span class="line">Partition 2 has been deleted.</span><br></pre></td></tr></table></figure>
</li>
<li><p>保存退出交互界面：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Command (m for help): w </span><br><span class="line">The partition table has been altered.</span><br><span class="line">Calling ioctl() to re-read partition table.</span><br><span class="line">Syncing disks.</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看磁盘信息：（<strong>会发现nvme0n2磁盘被分区</strong>）</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">[root@qv123 ~]# lsblk</span><br><span class="line">NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT</span><br><span class="line">sr0            11:0    1 10.2G  0 rom  </span><br><span class="line">nvme0n1       259:0    0   20G  0 disk </span><br><span class="line">|-nvme0n1p1   259:1    0    1G  0 part /boot</span><br><span class="line">`-nvme0n1p2   259:2    0   19G  0 part </span><br><span class="line">  |-rhel-root 253:0    0   17G  0 lvm  /</span><br><span class="line">  `-rhel-swap 253:1    0    2G  0 lvm  [SWAP]</span><br><span class="line">nvme0n2       259:3    0   10G  0 disk </span><br><span class="line">|-nvme0n2p1   259:6    0  300M  0 part </span><br><span class="line">`-nvme0n2p2   259:7    0    1K  0 part</span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="4-使用gdisk管理分区："><a href="#4-使用gdisk管理分区：" class="headerlink" title="4.使用gdisk管理分区："></a>4.使用gdisk管理分区：</h3><ul>
<li><p>gdisk命令工具默认将磁盘划分为GPT格式的分区</p>
</li>
<li><p>通过lsblk命令查看设备名：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">[root@qv123 ~]# lsblk</span><br><span class="line">NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT</span><br><span class="line">sr0            11:0    1 10.2G  0 rom  </span><br><span class="line">nvme0n1       259:0    0   20G  0 disk </span><br><span class="line">|-nvme0n1p1   259:1    0    1G  0 part /boot</span><br><span class="line">`-nvme0n1p2   259:2    0   19G  0 part </span><br><span class="line">  |-rhel-root 253:0    0   17G  0 lvm  /</span><br><span class="line">  `-rhel-swap 253:1    0    2G  0 lvm  [SWAP]</span><br><span class="line">nvme0n2       259:3    0   10G  0 disk</span><br></pre></td></tr></table></figure>
</li>
<li><p>使用gdisk命令，进入设备</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">gdisk /dev/设备名</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看帮助信息：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">Command (? for help): ?</span><br><span class="line">b       back up GPT data to a file</span><br><span class="line">c       change a partition&#x27;s name</span><br><span class="line">d       delete a partition</span><br><span class="line">i       show detailed information on a partition</span><br><span class="line">l       list known partition types</span><br><span class="line">n       add a new partition</span><br><span class="line">o       create a new empty GUID partition table (GPT)</span><br><span class="line">p       print the partition table</span><br><span class="line">q       quit without saving changes</span><br><span class="line">r       recovery and transformation options (experts only)</span><br><span class="line">s       sort partitions</span><br><span class="line">t       change a partition&#x27;s type code</span><br><span class="line">v       verify disk</span><br><span class="line">w       write table to disk and exit</span><br><span class="line">x       extra functionality (experts only)</span><br><span class="line">?       print this menu</span><br></pre></td></tr></table></figure>
</li>
<li><p>创建分区：(GPT分区没有主分区和扩展分区之说，最大支持1228个分区)</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">Command (? for help): n</span><br><span class="line">Partition number (2-128, default 2): 2    # 输入分区编号，默认为2，因为是硬盘的第一块分区</span><br><span class="line">First sector (34-20971486, default = 616448) or &#123;+-&#125;size&#123;KMGTP&#125;:    # 输入扇区的开始位置，选择默认即可，也可手动指定</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">输入扇区的结束位置，一般都是指定磁盘大小，这里输入+300M 表示新分区大小为300M</span></span><br><span class="line">Last sector (616448-20971486, default = 20971486) or &#123;+-&#125;size&#123;KMGTP&#125;: +300M</span><br><span class="line">Current type is &#x27;Linux filesystem&#x27;</span><br><span class="line">Hex code or GUID (L to show codes, Enter = 8300):    # 默认即可，分区完成后可以修改</span><br><span class="line">Changed type of partition to &#x27;Linux filesystem&#x27;</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看分区情况：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">Command (? for help): p</span><br><span class="line">Disk /dev/nvme0n2: 20971520 sectors, 10.0 GiB</span><br><span class="line">Model: VMware Virtual NVMe Disk</span><br><span class="line">Sector size (logical/physical): 512/512 bytes</span><br><span class="line">Disk identifier (GUID): F6277F8B-B83C-46B5-BDF5-3585DD416EFF</span><br><span class="line">Partition table holds up to 128 entries</span><br><span class="line">Main partition table begins at sector 2 and ends at sector 33</span><br><span class="line">First usable sector is 34, last usable sector is 20971486</span><br><span class="line">Partitions will be aligned on 2048-sector boundaries</span><br><span class="line">Total free space is 19742653 sectors (9.4 GiB)</span><br><span class="line"></span><br><span class="line">Number  Start (sector)    End (sector)  Size       Code  Name</span><br><span class="line">   1            2048          616447   300.0 MiB   8300  Linux filesystem</span><br><span class="line">   2          616448         1230847   300.0 MiB   8300  Linux filesystem</span><br></pre></td></tr></table></figure>
</li>
<li><p>保存退出：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">Command (? for help): w</span><br><span class="line"></span><br><span class="line">Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING</span><br><span class="line">PARTITIONS!!</span><br><span class="line"></span><br><span class="line">Do you want to proceed? (Y/N): y</span><br><span class="line">OK; writing new GUID partition table (GPT) to /dev/nvme0n2.</span><br><span class="line">The operation has completed successfully.</span><br></pre></td></tr></table></figure>
</li>
<li><p>使用lsblk命令查看磁盘信息：（可以发现nvme0n2磁盘被分为了三个分区）</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">[root@qv123 ~]# lsblk</span><br><span class="line">NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT</span><br><span class="line">sr0            11:0    1 10.2G  0 rom  </span><br><span class="line">nvme0n1       259:0    0   20G  0 disk </span><br><span class="line">|-nvme0n1p1   259:1    0    1G  0 part /boot</span><br><span class="line">`-nvme0n1p2   259:2    0   19G  0 part </span><br><span class="line">  |-rhel-root 253:0    0   17G  0 lvm  /</span><br><span class="line">  `-rhel-swap 253:1    0    2G  0 lvm  [SWAP]</span><br><span class="line">nvme0n2       259:3    0   10G  0 disk </span><br><span class="line">|-nvme0n2p1   259:4    0  300M  0 part </span><br><span class="line">|-nvme0n2p2   259:5    0  300M  0 part </span><br><span class="line">`-nvme0n2p3   259:6    0  500M  0 part</span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="5-使用parted划分分区："><a href="#5-使用parted划分分区：" class="headerlink" title="5.使用parted划分分区："></a>5.使用parted划分分区：</h3><ul>
<li><p>交互式：</p>
<ul>
<li><p>通过lsblk命令查看设备名：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">[root@qv123 ~]# lsblk</span><br><span class="line">NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT</span><br><span class="line">sr0            11:0    1 10.2G  0 rom  </span><br><span class="line">nvme0n1       259:0    0   20G  0 disk </span><br><span class="line">|-nvme0n1p1   259:1    0    1G  0 part /boot</span><br><span class="line">`-nvme0n1p2   259:2    0   19G  0 part </span><br><span class="line">  |-rhel-root 253:0    0   17G  0 lvm  /</span><br><span class="line">  `-rhel-swap 253:1    0    2G  0 lvm  [SWAP]</span><br><span class="line">nvme0n2       259:3    0   10G  0 disk</span><br></pre></td></tr></table></figure>
</li>
<li><p>使用parted命令，进入设备</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">parted /dev/设备名</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看帮助信息：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">(parted) help                                                             </span><br><span class="line">  align-check TYPE N                        check partition N for TYPE(min|opt) alignment</span><br><span class="line">  help [COMMAND]                           print general help, or help on COMMAND</span><br><span class="line">  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)</span><br><span class="line">  mkpart PART-TYPE [FS-TYPE] START END     make a partition</span><br><span class="line">  name NUMBER NAME                         name partition NUMBER as NAME</span><br><span class="line">  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found</span><br><span class="line">        partitions, or a particular partition</span><br><span class="line">  quit                                     exit program</span><br><span class="line">  rescue START END                         rescue a lost partition near START and END</span><br><span class="line">  resizepart NUMBER END                    resize partition NUMBER</span><br><span class="line">  rm NUMBER                                delete partition NUMBER</span><br><span class="line">  select DEVICE                            choose the device to edit</span><br><span class="line">  disk_set FLAG STATE                      change the FLAG on selected device</span><br><span class="line">  disk_toggle [FLAG]                       toggle the state of FLAG on selected device</span><br><span class="line">  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER</span><br><span class="line">  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER</span><br><span class="line">  unit UNIT                                set the default unit to UNIT</span><br><span class="line">  version                                  display the version number and copyright information of GNU Parted</span><br></pre></td></tr></table></figure>
</li>
<li><p>创建分区：(先创建分区表，再进行分区操作)</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">(parted) mklabel                                                          </span><br><span class="line">New disk label type? yes                                                  </span><br><span class="line">parted: invalid token: yes </span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">默认为msdos形式的分区，我们要正确分区大于2TB的磁盘，应该使用gpt方式的分区表，输入gpt后回车)</span>             </span><br><span class="line">New disk label type? gpt                                     </span><br><span class="line">Warning: The existing disk label on /dev/nvme0n2 will be destroyed and all data on this disk will be lost. Do you want</span><br><span class="line">to continue?</span><br><span class="line">Yes/No? yes                                                               </span><br><span class="line">(parted) mkpart      # 进行分区操作                                                       </span><br><span class="line">Partition name?  []? dp2             # 输入分区名称（自定义）   </span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="comment">#文件系统 （类型：ext4，ext3，ext2，xfs，其他...... ）</span></span></span><br><span class="line">File system type?  [ext2]?   </span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">开始位置 (0:设定当前分区的起始点为磁盘的第一个扇区;1G:设定当前分区的起始点为磁盘的1G处开始)</span></span><br><span class="line">Start? 0     </span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">结束位置（-1:设定当前分区的结束点为磁盘的最后一个扇区;10G:设定当前分区的结束点为磁盘的10G处）</span></span><br><span class="line">End? 10G                                                                  </span><br><span class="line">Warning: The resulting partition is not properly aligned for best performance: 34s % 2048s != 0s</span><br><span class="line">Ignore/Cancel?                                                            </span><br><span class="line">Ignore/Cancel? Ignore </span><br></pre></td></tr></table></figure>
</li>
<li><p>查看分区情况：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">(parted) p                                                                </span><br><span class="line">Model: NVMe Device (nvme)</span><br><span class="line">Disk /dev/nvme0n2: 10.7GB</span><br><span class="line">Sector size (logical/physical): 512B/512B</span><br><span class="line">Partition Table: gpt</span><br><span class="line">Disk Flags: </span><br><span class="line"></span><br><span class="line">Number  Start   End     Size     File system  Name  Flags</span><br><span class="line"> 1      17.4kB  10.0GB  10000MB  ext2         dp2</span><br></pre></td></tr></table></figure>
</li>
<li><p>保存退出：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">(parted) quit                                                             </span><br><span class="line">Information: You may need to update /etc/fstab.</span><br></pre></td></tr></table></figure>
</li>
<li><p>使用lsblk命令查看磁盘信息：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">[root@qv123 ~]# lsblk                                                     </span><br><span class="line">NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT</span><br><span class="line">sr0            11:0    1 10.2G  0 rom  </span><br><span class="line">nvme0n1       259:0    0   20G  0 disk </span><br><span class="line">|-nvme0n1p1   259:1    0    1G  0 part /boot</span><br><span class="line">`-nvme0n1p2   259:2    0   19G  0 part </span><br><span class="line">  |-rhel-root 253:0    0   17G  0 lvm  /</span><br><span class="line">  `-rhel-swap 253:1    0    2G  0 lvm  [SWAP]</span><br><span class="line">nvme0n2       259:3    0   10G  0 disk </span><br><span class="line">`-nvme0n2p1   259:5    0  9.3G  0 part </span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><p>非交互式：可将命令行写在脚本中，运行脚本实现一键创建；适用于远程批量管理多台主机的场景</p>
</li>
</ul>
<h3 id="6-格式化："><a href="#6-格式化：" class="headerlink" title="6.格式化："></a>6.格式化：</h3><ul>
<li><p>格式化的目的： 是为了形成文件系统，文件系统是操作系统用于明确存储设备或分区上的文件的方法和数据结构；即在存储设备上组织文件的方法。</p>
</li>
<li><p>命令格式： mkfs|mkfs.xfs|mkfs.ext4 [选项] 分区的设备名</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">[root@qv123 ~]# mkfs.ext4 /dev/nvme0n2p1</span><br><span class="line">mke2fs 1.45.6 (20-Mar-2020)</span><br><span class="line">Creating filesystem with 2441402 4k blocks and 610800 inodes</span><br><span class="line">Filesystem UUID: a30d3029-0a10-420f-808e-ed969017e0db</span><br><span class="line">Superblock backups stored on blocks: </span><br><span class="line">        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632</span><br><span class="line"></span><br><span class="line">Allocating group tables: done                            </span><br><span class="line">Writing inode tables: done                            </span><br><span class="line">Creating journal (16384 blocks): done</span><br><span class="line">Writing superblocks and filesystem accounting information: done </span><br></pre></td></tr></table></figure>
</li>
<li><p>选项：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">-t：文件系统类型——当命令名为mkfs时，指定要创建的文件系统的类型(如:xfs、ext4、vfat等)。当命令名为mkfs.xfs、mkfs.ext4等时，不需要该选项。</span><br><span class="line">-c：建立文件系统前先检查坏块。</span><br><span class="line">-V：输出建立文件系统的详细信息。</span><br></pre></td></tr></table></figure>
</li>
<li><p>注意：如果已有其他文件系统创建在此分区，必须在 mkfs.xfs 命令中加上选项 -f 强行进行格式化</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]# mkfs.xfs /dev/sda1</span><br><span class="line">[root@localhost ~]# mkfs.ext4 /dev/sda2</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查看格式化后的磁盘分区信息</span></span><br><span class="line">[root@localhost ~]# blkid</span><br><span class="line">/dev/sda1: UUID=&quot;350148b0-7975-4114-b91d-35ac1b211fd3&quot; BLOCK_SIZE=&quot;512&quot;</span><br><span class="line">TYPE=&quot;xfs&quot; PARTLABEL=&quot;primary&quot; PARTUUID=&quot;e272d830-5778-48cd-aba6-230271397716&quot;</span><br><span class="line">/dev/sda2: UUID=&quot;acf864ef-1778-4bc4-8e5d-260adfe38b69&quot; BLOCK_SIZE=&quot;4096&quot;</span><br><span class="line">TYPE=&quot;ext4&quot; PARTUUID=&quot;71ca21ff-cd76-a946-9dc6-4a8dd1022e99&quot;</span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="7-挂载：-格式化才能挂载"><a href="#7-挂载：-格式化才能挂载" class="headerlink" title="7.挂载：(格式化才能挂载)"></a>7.挂载：(格式化才能挂载)</h3><ul>
<li><p>挂载就是将一个分区或者设备挂载至挂载点目录</p>
</li>
<li><p>命令： mount [ -t 文件系统类型 ] 设备名 挂载点目录</p>
</li>
<li><p>挂载目录：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">[root@qv123 ~]# mount /dev/nvme0n2p1 /mnt</span><br><span class="line">[root@qv123 ~]# blkid</span><br><span class="line">/dev/nvme0n1p1: UUID=&quot;2a26a2b4-a069-4adf-a9cf-880ccc72962c&quot; BLOCK_SIZE=&quot;512&quot; TYPE=&quot;xfs&quot; PARTUUID=&quot;ce4159d8-01&quot;</span><br><span class="line">/dev/nvme0n1p2: UUID=&quot;AI2k3V-6Bfw-0WL0-UXAK-sRB3-JYLB-j6bybw&quot; TYPE=&quot;LVM2_member&quot; PARTUUID=&quot;ce4159d8-02&quot;</span><br><span class="line">/dev/sr0: BLOCK_SIZE=&quot;2048&quot; UUID=&quot;2021-10-13-03-57-25-00&quot; LABEL=&quot;RHEL-8-5-0-BaseOS-x86_64&quot; TYPE=&quot;iso9660&quot; PTUUID=&quot;4d694e6c&quot; PTTYPE=&quot;dos&quot;</span><br><span class="line">/dev/mapper/rhel-root: UUID=&quot;e3351e8b-648c-40fa-b343-5d50d8070dbe&quot; BLOCK_SIZE=&quot;512&quot; TYPE=&quot;xfs&quot;</span><br><span class="line">/dev/mapper/rhel-swap: UUID=&quot;d014eafb-cbb9-4776-aaf6-812eb2e16ad7&quot; TYPE=&quot;swap&quot;</span><br><span class="line">/dev/nvme0n2p1: UUID=&quot;a30d3029-0a10-420f-808e-ed969017e0db&quot; BLOCK_SIZE=&quot;4096&quot; TYPE=&quot;ext4&quot; PARTLABEL=&quot;dp2&quot; PARTUUID=&quot;229f8703-055b-4fa2-b591-d9b6f927a46b&quot;</span><br><span class="line">/dev/nvme0n1: PTUUID=&quot;ce4159d8&quot; PTTYPE=&quot;dos&quot;</span><br><span class="line">/dev/nvme0n2: PTUUID=&quot;ab36e107-8417-449f-a2a1-df2cee5646f8&quot; PTTYPE=&quot;gpt&quot;</span><br><span class="line">[root@qv123 ~]# mount | grep /dev/nvme0n2</span><br><span class="line">/dev/nvme0n2p1 on /mnt type ext4 (rw,relatime,seclabel)</span><br></pre></td></tr></table></figure>
</li>
<li><p>卸载分区，要移除USB磁盘、U盘、光盘和硬盘时，需要先卸载</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">umount 挂载点目录或存储设备名</span><br></pre></td></tr></table></figure>
</li>
<li><p>设置系统启动时的自动挂载手动挂载的分区会在系统重启后失效，若用户需要永久挂载分区，则需要通过<strong>编辑 &#x2F;etc&#x2F;fstab 文件</strong>来实现。当系统启动的时候，系统会自动地从这个文件读取信息，并且会自动将此文件中指定的文件系统挂载到指定的目录。</p>
<table>
<thead>
<tr>
<th>字段</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>设备文件</td>
<td>一般为设备的路径+设备名称，也可以写唯一识别码（UUID，Universally Unique Identifier）</td>
</tr>
<tr>
<td>挂载目录</td>
<td>指定要挂载到的目录，需在挂载前创建好</td>
</tr>
<tr>
<td>格式类型</td>
<td>指定文件系统的格式，比如Ext3、Ext4、XFS、SWAP、iso9660（此为光盘设备）等</td>
</tr>
<tr>
<td>权限选项</td>
<td>若设置为defaults，则默认权限为：rw, suid, dev, exec, auto, nouser, async</td>
</tr>
<tr>
<td>是否备份</td>
<td>若为1则开机后使用dump进行磁盘备份，为0则不备份</td>
</tr>
<tr>
<td>是否自检</td>
<td>若为1则开机后自动进行磁盘自检，为0则不自检</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@kongd ~]# tail -3 /etc/fstab</span><br><span class="line">/dev/mapper/rhel-root / xfs defaults 0 0</span><br><span class="line">UUID=806badd7-5a3b-4549-bcc1-3a43b07b6bac /boot xfs defaults 0 0</span><br><span class="line">/dev/mapper/rhel-swap swap swap defaults 0 0</span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="8-管理交换分区："><a href="#8-管理交换分区：" class="headerlink" title="8.管理交换分区："></a>8.管理交换分区：</h3><ul>
<li><p>在Linux系统中，swap交换分区的作用类似于Windows系统中“<strong>虚拟内存</strong>”。当有程序被调入内存后，但是该程序又不是常被CPU所取用时，那么这些不常被使用的程序将会被放到硬盘的swap交换分区当中，而将速度较快的内存空间释放给真正需要的程序使用，<strong>以避免由于物理内存不足</strong>而造成的系统效能低的问题。如果系统没有swap交换分区，或者现有交换分区的容量不够用时，可扩展swap交换分区。扩展swap交换分区的方式有两种：</p>
<ul>
<li>以磁盘分区的方式扩展swap交换分区</li>
<li>以镜像文件的方式扩展swap交换分区</li>
</ul>
</li>
<li><p>命令：</p>
<table>
<thead>
<tr>
<th>命令</th>
<th>功能</th>
</tr>
</thead>
<tbody><tr>
<td>mkswap 分区设备名</td>
<td>将指定的分区格式化为swap交换文件系统</td>
</tr>
<tr>
<td>swapon 交换分区设备名 | -a</td>
<td>启用(或激活)指定的交换分区或所有交换分区</td>
</tr>
<tr>
<td>swapoff 交换分区设备名 | -a</td>
<td>禁用指定的交换分区或所有交换分区</td>
</tr>
<tr>
<td>swapon -s</td>
<td>查看交换分区的使用情况</td>
</tr>
<tr>
<td>free -m</td>
<td>以兆字节为单位显示物理内存、交换分区的使用情况</td>
</tr>
</tbody></table>
<ul>
<li><p>新建分区扩展交换空间：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">格式化交换空间</span></span><br><span class="line">[root@localhost ~]#mkswap /dev/sda5</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">激活当前的交换空间</span></span><br><span class="line">[root@localhost ~]#swapon /dev/sda5</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">禁用指定的交换分区</span></span><br><span class="line">[root@localhost ~]#swapoff /dev/sdb1 关闭swap</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">查看当前激活的swap分区</span></span><br><span class="line">[root@localhost ~]#swapon -s</span><br><span class="line">[root@localhost ~]# cat /proc/swaps</span><br><span class="line">Filename Type Size Used Priority</span><br><span class="line">/dev/nvme0n1p3 partition 2097148 0 -2</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">写入/etc/fstab/,实现开机挂载</span></span><br><span class="line">[root@localhost ~]# vim /etc/fstab</span><br><span class="line">/dev/sda5 swap swap defaults 0 0</span><br></pre></td></tr></table></figure>
</li>
<li><p>新建文件扩展交换空间：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]# dd if=/dev/zero of=/swap bs=1M count=1024</span><br><span class="line">创建一个文件/swap，从无限零资源去读，每一块大小为1M，一共有1024块</span><br><span class="line">不能用cat去查看，不然会卡死（块设备）</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">格式化交换空间</span></span><br><span class="line">[root@localhost ~]# mkswap /swap</span><br><span class="line">[root@localhost ~]# swapon /swap</span><br><span class="line">[root@localhost ~]# chmod 0600 /swap</span><br><span class="line">[root@localhost ~]# swapon -s 查看当前的虚拟内存</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">写入/etc/fstab/,实现开机挂载</span></span><br><span class="line">[root@localhost ~]# vim /etc/fstab</span><br><span class="line">/swap swap swap defaults 0 0</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
<h2 id="2-查看磁盘空间使用量：df，du："><a href="#2-查看磁盘空间使用量：df，du：" class="headerlink" title="2.查看磁盘空间使用量：df，du："></a>2.查看磁盘空间使用量：df，du：</h2><ul>
<li><p>df：列出文件的<strong>文件系统</strong>的磁盘空间占用情况</p>
<p>df：disk free，通过文件系统来快速获取空间大小的信息，当我们删除一个文件的时候，这个文件不是马上就在文件系统当中消失了，而是暂时消失了，当所有程序都不用时，才会根据OS的规则释放掉已经删除的文件， df记录的是通过文件系统获取到的文件的大小，他比du强的地方就是能够看到已经删除的文件，而且计算大小的时候，把这一部分的空间也加上了，更精确了。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">-a(all)：  列出所有的文件系统，包括系统特有的/proc等文件系统</span><br><span class="line">-k(kb)：  以KB的容量显示各文件系统</span><br><span class="line">-m(mb)：  以MB的容量显示各文件系统</span><br><span class="line">-h(human)：  以人们较易阅读的GB,MB,KB等格式自行显示</span><br><span class="line">-H：  以M=1000K替代M=1024K的进位方式</span><br><span class="line">-T(type)：  连同该分区的文件系统名称（例如ext3）也列出</span><br><span class="line">-i(inodes)：  不用硬盘容量，而以inode的数量来显示</span><br><span class="line"></span><br><span class="line">由于df主要读取的数据几乎都是针对整个文件系统，因此读取的范围主要是在Super block内的信息，</span><br><span class="line">所以这个命令显示结果的速度非常快速。</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">df [-ahikHTm] [目录或文件名]</span><br></pre></td></tr></table></figure>
</li>
<li><p>du：显示<strong>文件</strong>磁盘空间使用量（统计目录或文件所占磁盘空间大小），在默认情况下，文件大小的单位是KB。</p>
<p>du，disk usage，是通过搜索文件来计算每个文件的大小然后累加，du能看到的文件只是一些当前存在的，没有被删除的。他计算的大小就是当前他认为存在的所有文件大小的累加和。当文件系统也确定删除了该文件后，这时候du与df就一致了</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">-a(all) :  列出所有的文件与目录容量，因为默认仅统计目录下面的文件量而已；</span><br><span class="line">-h(human) :  以人们较易读的容量格式（G/M）显示；</span><br><span class="line">-s() :  列出总量，而不列出每个个别的目录占用了容量；</span><br><span class="line">-S :  不包括子目录下的总计，与-s有点差别；</span><br><span class="line">-k(kb) :  以KB列出容量显示；</span><br><span class="line">-m(mb) :  以MB列出容量显示。</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">du [-ahskm] 文件或目录名称</span><br></pre></td></tr></table></figure></li>
</ul>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">Author: </span><span class="post-copyright-info"><a href="http://example.com">阿尔托莉雅</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">Link: </span><span class="post-copyright-info"><a href="http://example.com/2023/03/13/3.linux/A2.Linux%E5%88%9D%E7%BA%A7%E5%91%BD%E4%BB%A4/">http://example.com/2023/03/13/3.linux/A2.Linux%E5%88%9D%E7%BA%A7%E5%91%BD%E4%BB%A4/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">Copyright Notice: </span><span class="post-copyright-info">All articles in this blog are licensed under <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> unless stating additionally.</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Linux/">Linux</a></div><div class="post_share"><div class="social-share" data-image="/images/Otherwallpaper/avatar.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2023/03/13/3.linux/A3.Linux%E4%B8%AD%E7%BA%A7%E5%91%BD%E4%BB%A4/" title="Linux中级命令"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">Previous Post</div><div class="prev_info">Linux中级命令</div></div></a></div><div class="next-post pull-right"><a href="/2023/03/13/3.linux/A1.linux%E5%9F%BA%E7%A1%80/" title="Linux基础"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">Next Post</div><div class="next_info">Linux基础</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>Related Articles</span></div><div class="relatedPosts-list"><div><a href="/2023/03/13/3.linux/A1.linux%E5%9F%BA%E7%A1%80/" title="Linux基础"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-13</div><div class="title">Linux基础</div></div></a></div><div><a href="/2023/03/13/3.linux/A3.Linux%E4%B8%AD%E7%BA%A7%E5%91%BD%E4%BB%A4/" title="Linux中级命令"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-13</div><div class="title">Linux中级命令</div></div></a></div><div><a href="/2023/03/13/3.linux/A4.Shell%E8%84%9A%E6%9C%AC/" title="Shell脚本"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-13</div><div class="title">Shell脚本</div></div></a></div><div><a href="/2023/03/13/3.linux/B1.Docker%E5%AE%B9%E5%99%A8/" title="Docker容器"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-13</div><div class="title">Docker容器</div></div></a></div><div><a href="/2023/03/13/3.linux/C1.git%E5%B7%A5%E5%85%B7/" title="git工具"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-13</div><div class="title">git工具</div></div></a></div><div><a href="/2023/03/13/3.linux/D1.Ansible%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E5%B7%A5%E5%85%B7/" title="Ansible基础"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-13</div><div class="title">Ansible基础</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/images/Otherwallpaper/avatar.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">阿尔托莉雅</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">Articles</div><div class="length-num">11</div></a><a href="/tags/"><div class="headline">Tags</div><div class="length-num">4</div></a><a href="/categories/"><div class="headline">Categories</div><div class="length-num">2</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://toscode.gitee.com/blue-fantasy" target="_blank" title="Gitee"><i class="fab fa-github"></i></a><a class="social-icon" href="/1095322098@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>Announcement</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>Catalog</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#1-%E8%BF%9E%E6%8E%A5%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">1.</span> <span class="toc-text">1.连接命令：</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#2-%E7%B3%BB%E7%BB%9F%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">2.</span> <span class="toc-text">2.系统命令：</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E4%B8%BB%E6%9C%BA%E5%90%8D%E9%85%8D%E7%BD%AE%EF%BC%9A"><span class="toc-number">2.1.</span> <span class="toc-text">1.主机名配置：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-%E7%BD%91%E7%BB%9C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%EF%BC%9A"><span class="toc-number">2.2.</span> <span class="toc-text">2.网络服务管理：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-%E9%98%B2%E7%81%AB%E5%A2%99%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">2.3.</span> <span class="toc-text">3.防火墙命令：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-%E9%98%B2%E7%81%AB%E5%A2%99%E7%AB%AF%E5%8F%A3%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">2.4.</span> <span class="toc-text">4.防火墙端口命令：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-%E8%BF%9B%E7%A8%8B%E7%AE%A1%E7%90%86%E5%91%BD%E4%BB%A4"><span class="toc-number">2.5.</span> <span class="toc-text">5.进程管理命令</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-%E7%BD%91%E7%BB%9C%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">2.6.</span> <span class="toc-text">6.网络命令：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7-%E5%85%B6%E4%BB%96%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">2.7.</span> <span class="toc-text">7.其他命令：</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#3-%E7%94%A8%E6%88%B7%E5%92%8C%E7%94%A8%E6%88%B7%E7%BB%84%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">3.</span> <span class="toc-text">3.用户和用户组命令：</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E7%94%A8%E6%88%B7%E7%AE%A1%E7%90%86%E5%91%BD%E4%BB%A4"><span class="toc-number">3.1.</span> <span class="toc-text">1.用户管理命令</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-%E7%94%A8%E6%88%B7%E7%BB%84%E7%AE%A1%E7%90%86%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">3.2.</span> <span class="toc-text">2.用户组管理命令：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-%E6%9F%A5%E7%9C%8B%E7%94%A8%E6%88%B7%E7%99%BB%E5%BD%95%E7%B3%BB%E7%BB%9F%E7%9A%84%E6%83%85%E5%86%B5%EF%BC%9A"><span class="toc-number">3.3.</span> <span class="toc-text">3.查看用户登录系统的情况：</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#4-%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">4.</span> <span class="toc-text">4.常用命令：</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E5%88%97%E5%87%BA%E6%9F%90%E7%9B%AE%E5%BD%95%E6%96%87%E4%BB%B6%E5%88%97%E8%A1%A8%EF%BC%9A"><span class="toc-number">4.1.</span> <span class="toc-text">1.列出某目录文件列表：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-%E5%88%87%E6%8D%A2%E7%9B%AE%E5%BD%95%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">4.2.</span> <span class="toc-text">2.切换目录命令：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-%E5%88%9B%E5%BB%BA%E7%9B%AE%E5%BD%95%E5%92%8C%E7%A7%BB%E9%99%A4%E7%9B%AE%E5%BD%95%EF%BC%9A"><span class="toc-number">4.3.</span> <span class="toc-text">3.创建目录和移除目录：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-%E5%88%9B%E5%BB%BA%E6%96%87%E4%BB%B6%EF%BC%8C%E5%88%A0%E9%99%A4%E6%96%87%E4%BB%B6%EF%BC%8C%E6%9F%A5%E7%9C%8B%E6%96%87%E4%BB%B6%E8%AF%A6%E6%83%85%EF%BC%9A"><span class="toc-number">4.4.</span> <span class="toc-text">4.创建文件，删除文件，查看文件详情：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-%E6%98%BE%E7%A4%BA%E6%96%87%E4%BB%B6%E5%86%85%E5%AE%B9%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">4.5.</span> <span class="toc-text">5.显示文件内容命令：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-%E6%9F%A5%E7%9C%8B%E6%96%87%E4%BB%B6%E5%86%85%E5%AE%B9%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">4.6.</span> <span class="toc-text">6.查看文件内容命令：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#grep%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">4.6.1.</span> <span class="toc-text">grep命令：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#cut%E5%91%BD%E4%BB%A4%EF%BC%9A%E7%94%A8%E4%BA%8E%E6%8C%89%E5%88%97%E6%8F%90%E5%8F%96%E6%96%87%E6%9C%AC%E5%86%85%E5%AE%B9"><span class="toc-number">4.6.2.</span> <span class="toc-text">cut命令：用于按列提取文本内容</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#uniq%E5%91%BD%E4%BB%A4%EF%BC%9A%E5%8E%BB%E9%99%A4%E6%96%87%E6%9C%AC%E4%B8%AD%E8%BF%9E%E7%BB%AD%E7%9A%84%E9%87%8D%E5%A4%8D%E8%A1%8C"><span class="toc-number">4.6.3.</span> <span class="toc-text">uniq命令：去除文本中连续的重复行</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#tr%E5%91%BD%E4%BB%A4%EF%BC%9A%E6%9B%BF%E6%8D%A2%E6%96%87%E4%BB%B6%E4%B8%AD%E7%9A%84%E5%AD%97%E7%AC%A6%E6%98%BE%E7%A4%BA"><span class="toc-number">4.6.4.</span> <span class="toc-text">tr命令：替换文件中的字符显示</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#wc%E5%91%BD%E4%BB%A4%EF%BC%9A%E7%94%A8%E4%BA%8E%E7%BB%9F%E8%AE%A1%E6%8C%87%E5%AE%9A%E6%96%87%E6%9C%AC%E6%96%87%E4%BB%B6%E7%9A%84%E8%A1%8C%E6%95%B0%E3%80%81%E5%AD%97%E6%95%B0%E6%88%96%E5%AD%97%E8%8A%82%E6%95%B0"><span class="toc-number">4.6.5.</span> <span class="toc-text">wc命令：用于统计指定文本文件的行数、字数或字节数</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7-%E6%96%87%E4%BB%B6%E6%9F%A5%E6%89%BE%EF%BC%9A"><span class="toc-number">4.7.</span> <span class="toc-text">7.文件查找：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#find%E5%91%BD%E4%BB%A4%EF%BC%9A%E5%8F%AF%E6%8C%89%E7%85%A7%E6%96%87%E4%BB%B6%E5%90%8D%E3%80%81%E5%A4%A7%E5%B0%8F%E3%80%81%E6%97%B6%E9%97%B4%E3%80%81%E6%9D%83%E9%99%90%E3%80%81%E7%B1%BB%E5%9E%8B%E3%80%81%E6%89%80%E5%B1%9E%E8%80%85%E3%80%81%E6%89%80%E5%B1%9E%E7%BB%84%E6%9D%A5%E6%90%9C%E7%B4%A2%E6%96%87%E4%BB%B6%EF%BC%88%E8%BF%94%E5%9B%9E%E6%96%87%E4%BB%B6%E8%B7%AF%E5%BE%84%EF%BC%89"><span class="toc-number">4.7.1.</span> <span class="toc-text">find命令：可按照文件名、大小、时间、权限、类型、所属者、所属组来搜索文件（返回文件路径）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#which%E5%91%BD%E4%BB%A4%EF%BC%9Awhich-%E6%98%AF%E6%90%9C%E7%B4%A2%E7%B3%BB%E7%BB%9F%E5%91%BD%E4%BB%A4%E7%9A%84%E5%8F%AF%E6%89%A7%E8%A1%8C%E6%96%87%E4%BB%B6"><span class="toc-number">4.7.2.</span> <span class="toc-text">which命令：which 是搜索系统命令的可执行文件</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#8-%E8%A7%A3%E5%8E%8B%E7%BC%A9%E5%92%8C%E5%8E%8B%E7%BC%A9%EF%BC%9A"><span class="toc-number">4.8.</span> <span class="toc-text">8.解压缩和压缩：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#tar%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">4.8.1.</span> <span class="toc-text">tar命令：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#zip%E5%91%BD%E4%BB%A4%EF%BC%88%E5%8E%8B%E7%BC%A9%EF%BC%89%EF%BC%9A"><span class="toc-number">4.8.2.</span> <span class="toc-text">zip命令（压缩）：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#unzip%E5%91%BD%E4%BB%A4%EF%BC%88%E8%A7%A3%E5%8E%8B%E7%BC%A9%EF%BC%89%EF%BC%9A"><span class="toc-number">4.8.3.</span> <span class="toc-text">unzip命令（解压缩）：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#11-%E6%96%87%E4%BB%B6%E7%9B%AE%E5%BD%95%E5%89%AA%E5%88%87%E5%92%8C%E5%A4%8D%E5%88%B6%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">4.9.</span> <span class="toc-text">11.文件目录剪切和复制命令：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#12-%E6%97%B6%E9%97%B4%E6%93%8D%E4%BD%9C%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">4.10.</span> <span class="toc-text">12.时间操作命令：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-date%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">4.10.1.</span> <span class="toc-text">1.date命令：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-timedatectl%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">4.10.2.</span> <span class="toc-text">2.timedatectl命令：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#13-%E6%9F%A5%E7%9C%8B%E5%91%BD%E4%BB%A4%E5%B8%AE%E5%8A%A9%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">4.11.</span> <span class="toc-text">13.查看命令帮助命令：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#14-%E5%85%B6%E4%BB%96%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">4.12.</span> <span class="toc-text">14.其他命令：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#15-%E4%BF%AE%E6%94%B9%E5%AD%97%E7%AC%A6%E9%9B%86%E7%BC%96%E7%A0%81%EF%BC%9A"><span class="toc-number">4.13.</span> <span class="toc-text">15.修改字符集编码：</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#5-Vi%E5%92%8CVim%E7%BC%96%E8%BE%91%E5%99%A8%EF%BC%9A"><span class="toc-number">5.</span> <span class="toc-text">5.Vi和Vim编辑器：</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#6-%E6%95%B0%E6%8D%AE%E6%B5%81%E5%92%8C%E9%87%8D%E5%AE%9A%E5%90%91%E8%BE%93%E5%87%BA-gt-%E5%92%8C-gt-gt-%EF%BC%9A"><span class="toc-number">6.</span> <span class="toc-text">6.数据流和重定向输出&gt;和&gt;&gt;：</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#7-%E7%AE%A1%E9%81%93%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">7.</span> <span class="toc-text">7.管道命令：</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#8-Linux%E7%9A%84%E6%9D%83%E9%99%90%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">8.</span> <span class="toc-text">8.Linux的权限命令：</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E6%96%87%E4%BB%B6%E7%9A%84%E4%B8%80%E8%88%AC%E6%9D%83%E9%99%90%EF%BC%9A"><span class="toc-number">8.1.</span> <span class="toc-text">1.文件的一般权限：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-%E6%96%87%E4%BB%B6%E5%92%8C%E7%9B%AE%E5%BD%95%E7%9A%84%E7%89%B9%E6%AE%8A%E6%9D%83%E9%99%90%EF%BC%9A"><span class="toc-number">8.2.</span> <span class="toc-text">2.文件和目录的特殊权限：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-ACL%E6%9D%83%E9%99%90-%EF%BC%88%E6%8C%87%E5%AE%9A%E7%94%A8%E6%88%B7%E6%9D%83%E9%99%90%EF%BC%89"><span class="toc-number">8.3.</span> <span class="toc-text">3.ACL权限:（指定用户权限）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-%E6%9D%83%E9%99%90%E6%8E%A9%E7%A0%81umask%EF%BC%9A"><span class="toc-number">8.4.</span> <span class="toc-text">4.权限掩码umask：</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#10-%E7%AE%A1%E7%90%86Linux%E7%9A%84%E8%81%94%E7%BD%91%EF%BC%9A"><span class="toc-number">9.</span> <span class="toc-text">10.管理Linux的联网：</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E9%85%8D%E7%BD%AE%E7%BD%91%E8%B7%AF%EF%BC%9A"><span class="toc-number">9.1.</span> <span class="toc-text">1.配置网路：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#nmcli%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%B7%A5%E5%85%B7%EF%BC%9A"><span class="toc-number">9.1.1.</span> <span class="toc-text">nmcli命令行工具：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8nmtui%E9%85%8D%E7%BD%AE"><span class="toc-number">9.1.2.</span> <span class="toc-text">使用nmtui配置</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-%E7%BD%91%E7%BB%9C%E6%B5%8B%E8%AF%95%E5%91%BD%E4%BB%A4"><span class="toc-number">9.2.</span> <span class="toc-text">2.网络测试命令:</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-%E9%80%9A%E8%BF%87%E5%9F%9F%E5%90%8D%E8%AE%BF%E9%97%AE%E4%B8%BB%E6%9C%BA%EF%BC%9A"><span class="toc-number">9.3.</span> <span class="toc-text">3.通过域名访问主机：</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#11-%E4%BB%8E%E7%BD%91%E7%AB%99%E4%B8%8B%E8%BD%BD%E6%96%87%E4%BB%B6"><span class="toc-number">10.</span> <span class="toc-text">11.从网站下载文件:</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#12-%E8%BD%AF%E4%BB%B6%E5%8C%85%E7%AE%A1%E7%90%86RPM%E5%92%8CYUM%E6%95%B0%E6%8D%AE%E5%BA%93%EF%BC%9A"><span class="toc-number">11.</span> <span class="toc-text">12.软件包管理RPM和YUM数据库：</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E8%BD%AF%E4%BB%B6%E5%8C%85%E7%AE%A1%E7%90%86RPM%EF%BC%9A"><span class="toc-number">11.1.</span> <span class="toc-text">1.软件包管理RPM：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#rpm%E5%AE%89%E8%A3%85"><span class="toc-number">11.1.1.</span> <span class="toc-text">rpm安装</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#rpm%E6%9F%A5%E8%AF%A2%EF%BC%9A%EF%BC%88rpm-%E2%80%93q-%E5%B8%B8%E4%B8%8E%E4%B8%8B%E9%9D%A2%E5%8F%82%E6%95%B0%E7%BB%84%E5%90%88%E4%BD%BF%E7%94%A8%EF%BC%89"><span class="toc-number">11.1.2.</span> <span class="toc-text">rpm查询：（rpm –q 常与下面参数组合使用）</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-YUM%EF%BC%9A"><span class="toc-number">11.2.</span> <span class="toc-text">2.YUM：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E5%8C%85%E3%80%81%E5%8C%85%E7%BB%84%E7%9B%B8%E5%85%B3%E4%BF%A1%E6%81%AF%EF%BC%9A"><span class="toc-number">11.2.1.</span> <span class="toc-text">查看包、包组相关信息：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%89%E8%A3%85%E3%80%81%E6%9B%B4%E6%96%B0%E5%8C%85%E5%92%8C%E5%8C%85%E7%BB%84%EF%BC%9A"><span class="toc-number">11.2.2.</span> <span class="toc-text">安装、更新包和包组：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8D%B8%E8%BD%BD%E8%BD%AF%E4%BB%B6%E5%8C%85%EF%BC%9A"><span class="toc-number">11.2.3.</span> <span class="toc-text">卸载软件包：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%90%9C%E7%B4%A2%E6%96%87%E4%BB%B6%EF%BC%9A"><span class="toc-number">11.2.4.</span> <span class="toc-text">搜索文件：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B8%85%E7%A9%BA%E7%BC%93%E5%AD%98%EF%BC%9A"><span class="toc-number">11.2.5.</span> <span class="toc-text">清空缓存：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-%E6%BA%90%E4%BB%A3%E7%A0%81%E7%BC%96%E8%AF%91%EF%BC%9A"><span class="toc-number">11.3.</span> <span class="toc-text">3.源代码编译：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-%E8%BF%9B%E7%A8%8B%E7%AE%80%E4%BB%8B"><span class="toc-number">11.4.</span> <span class="toc-text">4.进程简介</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-%E6%9F%A5%E7%9C%8B%E8%BF%9B%E7%A8%8B%EF%BC%9A"><span class="toc-number">11.5.</span> <span class="toc-text">5.查看进程：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#ps%E5%91%BD%E4%BB%A4%E6%9F%A5%E7%9C%8B%E8%BF%9B%E7%A8%8B"><span class="toc-number">11.5.1.</span> <span class="toc-text">ps命令查看进程:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#top%E5%91%BD%E4%BB%A4%E6%9F%A5%E7%9C%8B%E8%BF%9B%E7%A8%8B%EF%BC%9A%EF%BC%88top-d-%E6%95%B0%E5%AD%97-bnp-%EF%BC%89%EF%BC%88%E5%8A%A8%E6%80%81%E6%9F%A5%E7%9C%8B%EF%BC%89"><span class="toc-number">11.5.2.</span> <span class="toc-text">top命令查看进程：（top [-d 数字] | [-bnp]）（动态查看）</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-%E4%BF%A1%E5%8F%B7%E6%8E%A7%E5%88%B6%E8%BF%9B%E7%A8%8B"><span class="toc-number">11.6.</span> <span class="toc-text">6.信号控制进程:</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7-%E4%BD%9C%E4%B8%9A%E6%8E%A7%E5%88%B6"><span class="toc-number">11.7.</span> <span class="toc-text">7.作业控制:</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#13-%E7%A3%81%E7%9B%98%E7%AE%A1%E7%90%86"><span class="toc-number">12.</span> <span class="toc-text">13.磁盘管理:</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E7%BB%B4%E6%8A%A4%E5%9F%BA%E6%9C%AC%E5%AD%98%E5%82%A8%E7%A9%BA%E9%97%B4"><span class="toc-number">12.1.</span> <span class="toc-text">1.维护基本存储空间:</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E5%88%86%E5%8C%BA%E7%9A%84%E4%B8%A4%E7%A7%8D%E6%A0%BC%E5%BC%8F"><span class="toc-number">12.1.1.</span> <span class="toc-text">1.分区的两种格式:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#MBR%E5%88%86%E5%8C%BA"><span class="toc-number">12.1.2.</span> <span class="toc-text">MBR分区:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#GPT%E5%88%86%E5%8C%BA"><span class="toc-number">12.1.3.</span> <span class="toc-text">GPT分区:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E6%9F%A5%E7%9C%8B%E7%A3%81%E7%9B%98%E4%BF%A1%E6%81%AF%EF%BC%88%E5%9D%97%E8%AE%BE%E5%A4%87%EF%BC%89"><span class="toc-number">12.1.4.</span> <span class="toc-text">2. 查看磁盘信息（块设备）:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-%E4%BD%BF%E7%94%A8fdisk%E7%AE%A1%E7%90%86%E5%88%86%E5%8C%BA"><span class="toc-number">12.1.5.</span> <span class="toc-text">3.使用fdisk管理分区:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-%E4%BD%BF%E7%94%A8gdisk%E7%AE%A1%E7%90%86%E5%88%86%E5%8C%BA%EF%BC%9A"><span class="toc-number">12.1.6.</span> <span class="toc-text">4.使用gdisk管理分区：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-%E4%BD%BF%E7%94%A8parted%E5%88%92%E5%88%86%E5%88%86%E5%8C%BA%EF%BC%9A"><span class="toc-number">12.1.7.</span> <span class="toc-text">5.使用parted划分分区：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-%E6%A0%BC%E5%BC%8F%E5%8C%96%EF%BC%9A"><span class="toc-number">12.1.8.</span> <span class="toc-text">6.格式化：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#7-%E6%8C%82%E8%BD%BD%EF%BC%9A-%E6%A0%BC%E5%BC%8F%E5%8C%96%E6%89%8D%E8%83%BD%E6%8C%82%E8%BD%BD"><span class="toc-number">12.1.9.</span> <span class="toc-text">7.挂载：(格式化才能挂载)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#8-%E7%AE%A1%E7%90%86%E4%BA%A4%E6%8D%A2%E5%88%86%E5%8C%BA%EF%BC%9A"><span class="toc-number">12.1.10.</span> <span class="toc-text">8.管理交换分区：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-%E6%9F%A5%E7%9C%8B%E7%A3%81%E7%9B%98%E7%A9%BA%E9%97%B4%E4%BD%BF%E7%94%A8%E9%87%8F%EF%BC%9Adf%EF%BC%8Cdu%EF%BC%9A"><span class="toc-number">12.2.</span> <span class="toc-text">2.查看磁盘空间使用量：df，du：</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>Recent Post</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/03/13/4.%E6%95%B0%E6%8D%AE%E5%BA%93/B3.NoSQL%E6%95%B0%E6%8D%AE%E5%BA%93%20-%20MongDB/" title="NoSQL篇-MongDB数据库">NoSQL篇-MongDB数据库</a><time datetime="2023-03-13T12:32:38.445Z" title="Created 2023-03-13 20:32:38">2023-03-13</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/03/13/4.%E6%95%B0%E6%8D%AE%E5%BA%93/B2.NoSQL%E6%95%B0%E6%8D%AE%E5%BA%93%20-%20Redis/" title="NoSQL篇-Redis数据库">NoSQL篇-Redis数据库</a><time datetime="2023-03-13T12:32:38.441Z" title="Created 2023-03-13 20:32:38">2023-03-13</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/03/13/4.%E6%95%B0%E6%8D%AE%E5%BA%93/A1.MySQL-%E6%AC%A7%E9%B9%8F%E7%AF%87/" title="SQL篇-MySQL数据库">SQL篇-MySQL数据库</a><time datetime="2023-03-13T12:32:38.437Z" title="Created 2023-03-13 20:32:38">2023-03-13</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/03/13/3.linux/D2.Ansible%E5%89%A7%E6%9C%AC/" title="Ansible">Ansible</a><time datetime="2023-03-13T12:32:23.866Z" title="Created 2023-03-13 20:32:23">2023-03-13</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/03/13/3.linux/D1.Ansible%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E5%B7%A5%E5%85%B7/" title="Ansible基础">Ansible基础</a><time datetime="2023-03-13T12:32:23.861Z" title="Created 2023-03-13 20:32:23">2023-03-13</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By 阿尔托莉雅</div><div class="framework-info"><span>Framework </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>Theme </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="Read Mode"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="Toggle Between Light And Dark Mode"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="Toggle between single-column and double-column"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="Setting"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="Table Of Contents"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="Back To Top"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>